public abstract SeekableByteChannel truncate (long size) throws IOException

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.

size     The new size, a non-negative byte count

Returns:  This channel

NonWritableChannelException     If this channel was not opened for writing
ClosedChannelException     If this channel is closed
IllegalArgumentException     If the new size is negative
IOException     If some other I/O error occurs