I am trying to delete a folder which has only files but no sub folders without success.
File rowFolder = new File(folderPath);
String[] files = r
Try this code
public class DeleteDirTest {
public static void main(String[] args) throws IOException {
DeleteDirTest test = new DeleteDirTest();
boolean result = test.deleteDir(new File("D:/test"));
System.out.println(result);
}
public boolean deleteDir(File file) {
if (file.isDirectory()) {
String[] children = file.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(file, children[i]));
if (!success) {
return false;
}
}
}
return file.delete();
}
}