Go (golang) Tutorials - Buffered File I/O

preview_player
Показать описание
#golang #go #input #output #file

File I/O - Buffered I/O
--------------------------
= Writing Data to File
= Reading from a File
= Appending to a File

----------------
package main
import ("os"
"bufio"
)
func main(){
file,err:=os.Create("newfile")
if err!=nil {
panic(err)
}
buf:=bufio.NewWriter(file) //Create a buffer for the os File
buf.WriteString("Writing Data to Buffer\n") //Write data to buffer
buf.Flush() //clears the buffer data and writes to the file
file.Close()
}

---------------
package main
import ("os"
"bufio"
"fmt"
)
func main(){
file,_:=os.Open("newfile")
reader:=bufio.NewReader(file)
data,_:=reader.Peek(50)
fmt.Println(string(data))
file.Close()
}

--------------
package main
import "os"
func main(){
//Opens an existing file with APPEND mode and Read/Write permission
file,err:=os.OpenFile("newfile",os.O_APPEND|os.O_WRONLY,0644)
if err !=nil {
panic(err)
}
file.WriteString("Trying to append\n")
file.Close()
}
Рекомендации по теме
Комментарии
Автор

Very useful video. Clearly explained what we need to know about buffer..Great job.

periyanayakisivaraj
Автор

very clear, concise content given. looking forward for upcoming videos

srinathvk
Автор

its really helpful for a beginner, good tutorials, where can i find gin tutorial mentioned in this video

krishnasai