golang overwrite file

package main

import (

func main() {
    // Specify the file path
    filePath := "example.txt"

    // Data to be written to the file
    newContent := []byte("This is the new content.")

    // Write the new content to the file, creating the file if it doesn't exist
    err := ioutil.WriteFile(filePath, newContent, 0644)
    if err != nil {
        fmt.Println("Error writing to file:", err)

    // Confirm the write operation
    fmt.Println("File overwritten successfully.")