Skip to content

Instantly share code, notes, and snippets.

@TomDeneire
Created October 15, 2022 08:56
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
file, openErr := os.Open("my_file.txt")
if openErr != nil {
panic(openErr)
}
defer file.Close()
scanner := bufio.NewScanner(file)
// Set the split function for the scanning operation.
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
// Error handling
scanErr := scanner.Err()
if scanErr != nil {
panic(scanErr)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment