Truncate () method truncates the file size. If the optional size argument is specified, the file is truncated to (maximum) that size. The default size corresponds to the current position. The current file position does not change. Note that if the specified size exceeds the current file size, the result is platform-dependent: the options are: the file can remain unchanged, grow to the specified size as if it were filled with zeros, or grow to the specified size with undefined new content.
To truncate a file, you can open the file in append or write mode.
See image below for file size.
Let’s change the file size to 100 bytes.
Note Note: to learn more about the statement,