- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to truncate a file in Java?
The flush() method of the FileWriter class flushes the contents of the file. You can use this method to truncate a file.
Example
import java.io.File; import java.io.FileWriter; public class FileTruncate { public static void main(String args[]) throws Exception { File file = new File("myData"); FileWriter fw = new FileWriter(file, false); fw.flush(); System.out.println("File truncated"); } }
Output
File truncated
- Related Articles
- How to truncate a file in C#?
- How we can truncate a file at a given size using Python?
- Truncate BigDecimal value in Java
- How to compress a file in Java?
- How to un-compress a file in Java?
- How to create a pdf file in Java?
- How to delete a temporary file in Java?
- How to convert a Kotlin source file to a Java source file?
- How to truncate an array in JavaScript?
- How to append data to a file in Java?
- How to truncate a string vector after a character in R?
- How to search a file in a directory in java
- How to convert File into a Stream in Java?
- How to open a plain text file in Java?
- How to truncate Key Length in Python Dictionary?

Advertisements