Go practiced hand OS file operation +os Package related

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

If the file does not exist, create the file, and if it exists, continue writing the file

package wrigeFileimport (    "fmt"    "github.com/golang/glog"    "os")//注意OpenFile这个方法的第二个参数,一定要加上RDWR,可读可写的权限func writeFile(s string) {    file1, err := os.OpenFile("test.txt", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660)    if err != nil {        panic(err)    }    defer file1.Close()    if err != nil {        fmt.Println(file1, err)        return    }    glog.Infoln(s)    file1.WriteString(s)    file1.Sync()}

OS Package Related information:
http://blog.csdn.net/chenbaoke/article/details/42494851
Http://blog.chinaunix.net/uid-24774106-id-3993609.html
Http://www.widuu.com/archives/01/921.html

Related Article

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.