Go Package bufio: Difference between revisions
Jump to navigation
Jump to search
Line 6: | Line 6: | ||
=Overview= | =Overview= | ||
The <code>bufio</code> package is aimed at buffering input in something faster (memory) while interacting with something slower (disk). | The <code>bufio</code> package is aimed at buffering input in something faster (memory) while interacting with something slower (disk). <code>bufio</code> is useful in situations when [[Queueing_Theory#Queueing_and_Overall_Pipeline_Performance|queueing improves the overall system performance]]. | ||
=Reading a Text File Line by Line= | =Reading a Text File Line by Line= |
Revision as of 18:42, 7 February 2024
External
Internal
Overview
The bufio
package is aimed at buffering input in something faster (memory) while interacting with something slower (disk). bufio
is useful in situations when queueing improves the overall system performance.
Reading a Text File Line by Line
import (
"bufio"
"os"
)
f, err := os.Open("/Users/ovidiu/tmp/sometext.txt")
if err != nil {
...
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
line := scanner.Text()
...
}