Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Last active April 25, 2021 18:20
Show Gist options
  • Select an option

  • Save Ramko9999/cd7b4660a30fb1eeaa8ded550da46087 to your computer and use it in GitHub Desktop.

Select an option

Save Ramko9999/cd7b4660a30fb1eeaa8ded550da46087 to your computer and use it in GitHub Desktop.
import (
"log"
"os"
)
/*
append.txt initally:
An existing line
append.txt after calling appendToFile:
An existing line
Adding a new line
*/
func appendToFile(){
content := "\nAdding a new line";
file, err := os.OpenFile("append.txt", os.O_APPEND | os.O_WRONLY, 0644);
defer file.Close();
if err != nil {
log.Fatal(err);
}
file.Write([]byte(content));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment