Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Working with Files & I/O | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 10 of 60

·Go

Working with Files & I/O

20 minutes

Course progress17%

File I/O

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

The os and io packages provide the building blocks for reading and writing.

// Write a string to a file
f, err := os.Create("out.txt")
if err != nil { log.Fatal(err) }
defer f.Close()
_, err = f.WriteString()
"Hello, Go! "

Buffered I/O

buf := bufio.NewReader(f)
line, err := buf.ReadString('
')

Working with JSON

type Config struct {
    Port int `json:"port"`
    Debug bool `json:"debug"`
}

var cfg Config
data, _ := os.ReadFile("config.json")
json.Unmarshal(data, &cfg)

Copying files (one‑liner)

io.Copy(dst, src) // src and dst must implement io.Reader / io.Writer

Info

Always check for errors – ignoring them can lead to data loss.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonPointers, Allocation, and the Garbage CollectorContinue to lesson 11Testing in Go: The `testing` PackageBack to Go Programming Bootcamp curriculum