In this tutorial, I am sharing simple program about How to delete a file in Java.
To delete the file using Java, We have to call the predefined method called delete(). Which is actually belongs to java.io.File class. This is method will return boolean value such as true If the file is deleted successfully from the file system. It will return false If the file is not exist in the specified path.
FileDeletionExample.java
package com.dineshkrish.files; import java.io.File; public class FileDeletionExample { public static void main(String[] args) { // Defining the File Object File file = new File("abc.txt"); // Calling the method delete() boolean flag = file.delete(); if(flag) { System.out.println("The File is Deleted Successfully!!!!"); } else { System.out.println("The File is not exist."); } } }
References
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet