Files
Advanced · Standard Library & I/O
Reading and writing files — everyday real-world I/O.
- files1 — whole-file I/O with
os.WriteFile/os.ReadFile - files2 — streaming line by line with
bufio.Scanner
Resources
Section titled “Resources”Exercises
Section titled “Exercises”files1 test
Section titled “files1 test”files1 — reading and writing files
Show hint
Whole-file I/O:
os.WriteFile(path, []byte(content), 0o644)data, err := os.ReadFile(path); return string(data), errfiles2 test
Section titled “files2 test”files2 — reading line by line with bufio.Scanner
Show hint
Scan advances one line per call:
for scanner.Scan() { n++ }