Go code
data, err := os.ReadFile("note.txt")
if err != nil {
fmt.Println("Could not read file")
return
}
fmt.Println(string(data))Line-by-line explanation
- ReadFile requests all bytes from note.txt.
- Err is checked immediately.
- String converts bytes to text.
- The content is displayed.
Expected output
Hello from the fileThis assumes note.txt contains that sentence.