截断文件时,它会在开始时添加额外的零字节:
configFile, err := os.OpenFile("./version.json", os.O_RDWR, 0666)
defer configFile.Close()
check(err)
//some actions happen here
configFile.Truncate(0)
configFile.Write(js)
configFile.Sync()
Run Code Online (Sandbox Code Playgroud)
结果,文件具有我0在开头用一段字节写的内容.
如何在没有前导零的情况下截断并完全重写文件?
go ×1