Delete All Files using Java

To delete all files using java we can simply use the delete() method available in java.io.File package. First we have to list all the file in directory using the File.listFiles() method and then simply use the File.delete() method to delete the files inside the directory.

below exapmle demostrates that how to delete all files inside a directory

output:-

Leave a Reply

Your email address will not be published. Required fields are marked *