truncate
truncate(file,n)
Resize the file or buffer given by the first argument to exactly n
bytes, filling previously unallocated space with '\0' if the file or buffer is grown
Examples
truncate(file::AbstractString, n::Integer)
Truncate the file specified by the file
path to exactly n
bytes. If the file size is increased, the previously unallocated space is filled with '0'
characters. This function returns nothing.
buffer = IOBuffer("Hello, World!")
truncate(buffer, 10)
This example truncates the buffer to exactly 10 bytes. If the buffer size is increased, the additional space will be filled with '0'
characters.
truncate("data.txt", 100)
In this example, the file "data.txt"
is truncated to exactly 100 bytes. If the file size is increased, the additional space will be filled with '0'
characters.
Note: The truncate
function is usually used with files or buffers, and the n
argument should be an integer representing the desired size in bytes.
See Also
abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.