使用go语言实现文件创建于写入
package main
import (
"fmt"
"io"
"os"
)
func main() {
f, err := os.OpenFile("test.txt", os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
fmt.Println("OpenFile Err!")
}
defer f.Close()
_, err = f.WriteString("123##90####rn hello world\n")
_, err = f.WriteString("123##90####rn hello world\n")
_, err = f.WriteString("123##90####rn hello world\n")
if err != nil {
fmt.Println("Write string error", err)
}
off, _ := f.Seek(0, io.SeekEnd)
_, err = f.WriteString("abc")
fmt.Println("Write string OK")
if err != nil {
fmt.Println("Write string error", err)
}
// 从最后位置写入
_, err = f.WriteAt([]byte("111111111111"), off)
}