public void setLength(long newLength) throws IOException {
        if (newLength < 0) {
            throw new IllegalArgumentException("newLength < 0");
        }
        try {
            Libcore.os.ftruncate(fd, newLength);
        } catch (ErrnoException errnoException) {
            throw errnoException.rethrowAsIOException();
        }

        long filePointer = getFilePointer();
        if (filePointer > newLength) {
            seek(newLength);
        }

        // if we are in "rws" mode, attempt to sync file+metadata
        if (syncMetadata) {
            fd.sync();
        }
    }
public void setLength ( long newLength ) throws IOException { if ( newLength < 0 ) { throw new IllegalArgumentException ( "newLength < 0" ) ; } try { Libcore . os . ftruncate ( fd , newLength ) ; } catch ( ErrnoException errnoException ) { throw errnoException . rethrowAsIOException ( ) ; } long filePointer = getFilePointer ( ) ; if ( filePointer > newLength ) { seek ( newLength ) ; } if ( syncMetadata ) { fd . sync ( ) ; } }
Sets the length of this file to {@code newLength}. If the current file is
smaller, it is expanded but the contents from the previous end of the
file to the new end are undefined. The file is truncated if its current
size is bigger than {@code newLength}. If the current file pointer
position is in the truncated part, it is set to the end of the file.

@param newLength
the new file length in bytes.
@throws IllegalArgumentException
if {@code newLength < 0}.
@throws IOException
if this file is closed or another I/O error occurs.