Skip to content

Instantly share code, notes, and snippets.

@yakuter
Created February 15, 2024 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakuter/08264468a52dab884ab604ded3488790 to your computer and use it in GitHub Desktop.
Save yakuter/08264468a52dab884ab604ded3488790 to your computer and use it in GitHub Desktop.
Copy and Movement 9
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
file, err := os.Open("example.txt")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer file.Close()
// Create a buffered reader
scanner := bufio.NewScanner(file)
// Read the file line by line
for scanner.Scan() {
line := scanner.Text()
fmt.Println(line)
}
// Check for errors during scanning
if err := scanner.Err(); err != nil {
fmt.Println("Error reading file:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment