package main
import (
"bufio"
"log"
"os"
)
func main() {
// Open the file
file, err := os.Open("filename.txt")
if err != nil {
log.Fatalf("Error opening file: %s", err)
}
defer file.Close()
// Create a scanner to read the file line by line
scanner := bufio.NewScanner(file)
// Iterate over each line in the file
for scanner.Scan() {
line := scanner.Text()
println(line)
// print(line)
// log.Println(line)
}
// Check for errors while scanning the file
if err := scanner.Err(); err != nil {
log.Fatalf("Error reading file: %s", err)
}
}
Created
March 1, 2023 02:41
-
-
Save scriptkkiddie/9256fe1590cb10c9f9b25f8fe4524a0a to your computer and use it in GitHub Desktop.
File Reader Prototype in Golang
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment