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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 34 of 60 · Go

File System Operations with `os` and `io/ioutil`

Duration: 15 minutes

FS Helpers

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

Create, read, write, and delete files.

// Write a file
err := os.WriteFile("out.txt", []byte("hello"), 0644)

// Read a file
data, err := os.ReadFile("out.txt")

// Append to a file
f, _ := os.OpenFile("out.txt", os.O_APPEND|os.O_WRONLY, 0644)
defer f.Close()
f.WriteString("\nmore")

Directory traversal

dir, _ := os.ReadDir(".")
for _, entry := range dir {
    fmt.Println(entry.Name(), entry.IsDir())
}

Temporary files

tmp, _ := os.CreateTemp("", "prefix-*.tmp")
defer os.Remove(tmp.Name())

Info

When using ioutil (deprecated) switch to the newer os and io functions introduced in Go 1.16.

Previous: Working with Environment VariablesNext: Time Package – Parsing, Formatting, and Timers