Omar Omar - 1 year ago 75
Java Question

How to delete the contents of a file using the FileOutputStream class in Java?

I'm work with the FileOutputStream class in java, but I don't know how to delete the contents of a file (the main reason i need overwrite the file).... Thanks for your responses !

Answer Source

Call File.delete() which deletes the file or directory denoted by this abstract pathname.

File f = new File("foo.txt");
if (f.delete()) {
    System.out.println("file deleted");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download