Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // Snippet: OpenFile with more options. Last param is the permission mode
  2. // Second param is the attributes when opening
  3. // Use these attributes individually or combined
  4. // with an OR for second arg of OpenFile()
  5. // e.g. os.O_CREATE|os.O_APPEND
  6. // or os.O_CREATE|os.O_TRUNC|os.O_WRONLY
  7. // os.O_RDONLY // Read only
  8. // os.O_WRONLY // Write only
  9. // os.O_RDWR // Read and write
  10. // os.O_APPEND // Append to end of file
  11. // os.O_CREATE // Create is none exist
  12. // os.O_TRUNC // Truncate file when opening
  13.  
  14. file, err := os.OpenFile("test.txt", os.O_APPEND, 0666)
  15. if err != nil {
  16. log.Fatal(err)
  17. }
  18. defer func() { _ = file.Close() }()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement