truncate

abstract fun truncate(size: Long): SeekableByteChannel

Truncates the entity, to which this channel is connected, to the given size.

If the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end. If the given size is greater than or equal to the current size then the entity is not modified. In either case, if the current position is greater than the given size then it is set to that size.

An implementation of this interface may prohibit truncation when connected to an entity, typically a file, opened with the APPEND option.

Return

This channel

Parameters

size

The new size, a non-negative byte count

Throws

NonWritableChannelException

If this channel was not opened for writing

If this channel is closed

If the new size is negative

IOException

If some other I/O error occurs