写二进制数据
func WriteFile(filepath string) {
file,err := os.OpenFile(filepath,os.O_CREATE|os.O_APPEND,os.ModePerm)
if err != nil{
return 0,err
}
defer file.Close()
bs := []byte{65,66,67,68,69,70}
n,err := file.Write(bs)
if err != nil{
return 0,err
}
fmt.Println(n)
}
写字符串数据
func writeFile(filepath string,info string){
file,err := os.OpenFie(filepath,os.O_CREATE|os.O_APPEND,os.ModePerm)
if err != nil {
return 0,err
}
defer file.Close()
n,err := file.WriteString(info)
if err != nil{
return 0,err
}
fmt.Println(n)
}
缓冲区写数据
func wirteFile(filepath string,info string){
file,err := os.OpenFile(filepath,os.O_CREATE|os.O_RDWR, os.ModePerm)
if err != nil{
fmt.Println(err)
return
}
w1 := bufio.NewWriter(file)
w1.WriteString(info)
w1.flush()
}