The ideal environment for Golang is the Linux system, with faster compilation speed and execution speed, this article is about the file manipulation function in Golang
The OS package in the Golang standard library provides an excuse for not relying on a platform, but the style used is UNIX-style.
The function OpenFile is an option that can be specified (the constant is the same as the file manipulation function in Linux, such as O_append), the specified pattern such as 0666, and so on, opens the specified file
Here is the prototype Golang code for the OpenFile function
1 func stringint, perm FileMode) (File *file,err error)
Where name is the file name of the file, if it is not currently running the path of the program, you need to add a path, flag is the processing parameters of the file, is the type of int different systems specific how much may be different, but the effect is the same. Give a few constants that are usually used
1 o_rdonly: Read-only2 o_wronly: Write only3 o_rdwr: Read and write4 o_append: Append5 o_create: Does not exist, then creates6 O_EXCL: If the file exists and the o_create is calibrated, an error is generated7 O_trung: If the file exists and it is successfully opened as write-only or read-write, its length is cropped only. (overwrite)8 O_noctty If the file name represents an end device, it is not set to the control device that invokes the process:9O_nonblock: If the filename represents a FIFO, or a block device, the character device file is in a later file and i/O operation in non-blocking modeTenO_sync: When a series of writes are performed, each time you wait for the last I/O operation to complete.
Although we identify them in the form of characters, they are essentially data of type int. Also represents the permissions of files in Linux in FileMode