Read and write are not the only operations that can be executed on a file. In the following section, we'll look at how to use them using the os package.
Other operations
Create
In order to create an empty file, we can call a helper function called Create, which opens a new file with a 0666 permission and truncates it if it doesn't exist. Alternatively, we can use OpenFile with the O_CREATE|O_TRUNCATE mode to specify custom permissions, as shown in the following code:
package main
import "os"
func main() {
f, err := os.Create("file.txt")
if err != nil {
fmt.Println("Error:", err)
return
}
f.Close()
}