Created
February 15, 2024 20:24
-
-
Save yakuter/08264468a52dab884ab604ded3488790 to your computer and use it in GitHub Desktop.
Copy and Movement 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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