Java examples for File Path IO:File delete
To delete a file, create a File object for the file, and then call the delete method.
If the file is a directory, the directory must be empty to be deleted.
import java.io.File; import java.io.IOException; public class Main { public static void main(String[] arg) throws IOException { File f = new File("myfile.txt"); if (f.delete()) System.out.println("File deleted."); else/*from w w w. ja v a 2 s. co m*/ System.out.println("File not deleted."); } }