Using file.delete() to delete a file in Java IO

Deleting a file permanently in Java is dead simple that it is just a method away from it. The file.delete() method in the lets you do this. Here is the example.

class DeleteFile
public static void main(String args[])
File f=new File("myfile.txt");
// Print file name
System.out.println("The file to be deleted is "+f.getName());
// Delete the file
delete(): The delete method when called deletes the file permanently, if it exists. You can alternatively check its existence by using the exist() method in the class.

The file to be deleted is myfile.txt

Posted by at on

Tags: Java IO,