File Operations in Go: Difference between revisions
Jump to navigation
Jump to search
(24 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[Go Code Examples#Code_Examples|Go Code Examples]] | * [[Go Code Examples#Code_Examples|Go Code Examples]] | ||
* [[Go Package os]] | |||
* [[Go Package ioutil]] | * [[Go Package ioutil]] | ||
* [[Go Package | * [[Go Package io]] | ||
* [[Go Package bufio]] | |||
* [[File_Paths_and_Names_in_Go#path|Go Package path]] | |||
* [[File_Paths_and_Names_in_Go#filepath|Go Package filepath]] | |||
=Overview= | =Overview= | ||
The [[Go Package os#Overview|<tt>os</tt> package]] provides practical file access functions. | |||
Basic file read and write, by reading or writing the entire file into and from memory, is also provided by the [[Go Package ioutil|<tt>ioutil</tt> package]], but its <code>[[Go Package ioutil#Overview|ioutil.ReadFile]]</code> and <code>[[Go Package ioutil#Overview|ioutil.WriteFile]]</code> are deprecated since Go 1.16. | |||
<span id='Line_by_Line'></span>The [[Go Package bufio#Overview|<tt>bufio</tt> package]] can be used to [[Go_Package_bufio#Reading_a_Text_File_Line_by_Line|read a text file line by line]]. | |||
<span id='File_Paths_and_Names_in_Go'></span>File paths and names should be manipulated with the functions exposed by the <code>[[File_Paths_and_Names_in_Go#path|path]]</code> and <code>[[File_Paths_and_Names_in_Go#filepath|filepath]]</code> packages, explained here: {{Internal|File Paths and Names in Go#Overview|File Paths and Names in Go}} |
Latest revision as of 21:06, 29 February 2024
Internal
- Go Code Examples
- Go Package os
- Go Package ioutil
- Go Package io
- Go Package bufio
- Go Package path
- Go Package filepath
Overview
The os package provides practical file access functions.
Basic file read and write, by reading or writing the entire file into and from memory, is also provided by the ioutil package, but its ioutil.ReadFile
and ioutil.WriteFile
are deprecated since Go 1.16.
The bufio package can be used to read a text file line by line.
File paths and names should be manipulated with the functions exposed by the path
and filepath
packages, explained here: