===== os.Open ===== ==== What is it? ==== `os.Open(name)` opens the named file for reading and returns an `*os.File`. ==== What is it used for? ==== * Read file contents. * Work with file handles for streaming reads. ==== Example ==== f, err := os.Open("data.txt") if err != nil { return err } defer f.Close() b, err := io.ReadAll(f) if err != nil { return err } _ = b ==== Notes ==== * Always `defer f.Close()` to release resources. * For read+write or create, use `os.OpenFile` with flags. * For small files, `os.ReadFile` is a convenient helper. ==== Related pages ==== * [[go:stdlib:os_readfile|os.ReadFile]] * [[go:stdlib:os_openfile|os.OpenFile]] * [[go:stdlib:os_create|os.Create]] ==== Hard words (English) ==== * **handle** /ˈhændl/: tay cầm file (descriptor) * **streaming** /ˈstriːmɪŋ/: đọc theo luồng (từng phần) * **release** /rɪˈliːs/: giải phóng * **flag** /flæɡ/: cờ tuỳ chọn