Use FileChannel.truncate:
try (FileChannel outChan = new FileOutputStream(f, true).getChannel()) {
outChan.truncate(newSize);
}
More Related Contents:
- Write byte array to file in java
- How to move elements of Java ArrayList to file in java [closed]
- How do I create a Java string from the contents of a file?
- How do I save a String to a text file using Java?
- Java IO implementation of unix/linux “tail -f”
- How to create a temporary directory/folder in Java?
- Reliable File.renameTo() alternative on Windows?
- What is simplest way to read a file into String? [duplicate]
- Inserting text into an existing file via Java
- How to Write text file Java
- Java FileOutputStream Create File if not exists
- How do I use Java to read from a file that is actively being written to?
- Elegant way to read file into byte[] array in Java [duplicate]
- Check line for unprintable characters while reading text file
- Writing a file to sdcard
- Whole text file to a String in Java
- Java BufferedReader back to the top of a text file?
- java IO to copy one File to another
- How to append data to a file?
- Reading from a text file and storing in a String [duplicate]
- Write String with preceding zeros into CSV file in java
- Java : How to determine the correct charset encoding of a stream
- Best way to list files in Java, sorted by Date Modified?
- Using File.listFiles with FileNameExtensionFilter
- Java ‘file.delete()’ Is not Deleting Specified File
- How to create a new java.io.File in memory? [duplicate]
- Java scanner not going through entire file
- Using bash, how do you make a classpath out of all files in a directory?
- Java read file and store text in an array
- Getting directory path to .class file containing main