How to read/write from/to file using Go?

前端 未结 8 1051
慢半拍i
慢半拍i 2020-11-28 17:23

I\'ve been trying to learn Go on my own, but I\'ve been stumped on trying read from and write to ordinary files.

I can get as far as inFile, _ := os.Open(INFIL

8条回答
  •  渐次进展
    2020-11-28 17:44

    Try this:

    package main
    
    import (
      "io"; 
      )
    
    
    func main() {
      contents,_ := io.ReadFile("filename");
      println(string(contents));
      io.WriteFile("filename", contents, 0644);
    }
    

提交回复
热议问题