In Go language, you are allowed to truncate the size of the file with the help of the Truncate() function. This function is used to truncate the size of the given file in the specified size.
- If the given file is a symbolic link, then it changes the size of the link’s target.
- If this method throws an error, then it will be of type *PathError.
- It is defined under the os package so, you have to import os package in your program for accessing Truncate() function.
- Suppose if the truncate file if of 100 bytes and the original file is less than 100 bytes, then the original content remains at the beginning and the remaining space is filled with the null bytes. And if the original file is greater than 100 bytes, then the truncated file lost content after 100 bytes.
- If you pass 0 in the Truncate() function, then you will get an empty file.
func Truncate(name string, size int64) error
- time.Truncate() Function in Golang With Examples
- time.Time.Truncate() Function in Golang with Examples
- How to Create an Empty File in Golang?
- How to Rename and Move a File in Golang?
- How to Delete or Remove a File in Golang?
- Checking the Given File Exists or Not in Golang
- How to Read a File Line by Line to String in Golang?
- How to Uncompress a File in Golang?
- How to convert a slice of bytes in uppercase in Golang?
- Golang program that uses fallthrough keyword
- math.Lgamma() Function in Golang with Examples
- math.Float64bits() Function in Golang With Examples
- How to check equality of slices of bytes in Golang?
- atomic.AddInt64() Function in Golang With Examples
- atomic.StoreInt64() Function in Golang With Examples
- reflect.FieldByIndex() Function in Golang with Examples
- string.Contains Function in Golang with Examples
- bits.Sub() Function in Golang with Examples
- How to convert a slice of bytes in lowercase in Golang?
- io.PipeWriter.CloseWithError() Function in Golang with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.