os.Chmod() function can be used to change the permissions of an existing file. Below is the signature of the function Code Output:
Tag: file
Make a copy of a file in Go (Golang)
In this article we will see two methods of copying a file. First Method io.Copy() can be used to create a copy of the file from src to dest. A successful copy…
Rename file or folder in Go (Golang)
Overview os.Rename() function can be used to rename a file or folder. Below is the signature of the function. old and new can be fully qualified as well. If the old and…
Create an empty file in Go (Golang)
Overview os.Create() can be used to create an empty file in go. The signature of the function is Basically this function Create a named file with mode 0666 It truncates the file…
Append to an existing file in Go (Golang)
os.OpenFile() function of the os package can be used to open to a file in an append mode and then write to it Let’s see an example. In the below program: First,…
Touch a file in Go (Golang)
Touching a file means Create an empty file if the file doesn’t already exist If the file already exists then update the modified time of the file. Output: When running the first…
Read a large file Line by Line in Go (Golang)
When it comes to reading large files, obviously we don’t want to load the entire file in memory. bufio package in golang comes to the rescue when reading large files. Let’s say…