Golang ProgramsGolang Programs

Reduce file size

os.Truncate() function will reduce the file content upto N bytes passed in second parameter. In below example if size of test.txt file is more that 1Kb(100 byte) then it will truncate the remaining content.
package main
import (
func main() {
	err := os.Truncate("test.txt", 100)
	if err != nil {
C:\golang\working-with-files>go fmt example10.go

C:\golang\working-with-files>golint example10.go

C:\golang\working-with-files>go run example10.go