Golang file handler function OpenFile coupling with file functions of Linux System

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.