上QQ阅读APP看书,第一时间看更新
Truncate
To truncate the content of a file under a certain dimension, and leave the file untouched if it's smaller, there is the os.Truncate method. Its usage is pretty simple, as shown in the following code:
package main
import "os"
func main() {
// let's keep thing under 4kB
if err := os.Truncate("file.txt", 4096); err != nil {
fmt.Println("Error:", err)
}
}