To delete the files in a folder using java, the following piece of code can be used.
The folder itself can also be deleted by adding the following line after the for loop.
String path = "Path\\to\\target\\folder\\"; File folder = new File(path); File[] listOfFiles = folder.listFiles(); //Iterate through the files for (File f : listOfFiles) { f.delete(); }
The folder itself can also be deleted by adding the following line after the for loop.
folder.delete();
No comments:
Post a Comment