How can I close bufio.Reader
or bufio.Writer
in golang?
func init(){
file,_ := os.Create("result.txt")
writer = bufio.NewWriter(file)
}
Should I close Writer
? or just use file.Close()
will make Writer
close?
How can I close bufio.Reader
or bufio.Writer
in golang?
func init(){
file,_ := os.Create("result.txt")
writer = bufio.NewWriter(file)
}
Should I close Writer
? or just use file.Close()
will make Writer
close?
As far as I know, you can't close the bufio.Writer
.
What you do is to Flush()
the bufio.Writer
and then Close()
the os.Writer
:
writer.Flush()
file.Close()