Java examples for File Path IO:Directory Create
Create a method that deletes a non-empty directory
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"); deleteFile(f);//w w w .ja v a 2s . co m } private static void deleteFile(File dir) { File[] files = dir.listFiles(); for (File f : files) { if (f.isDirectory()) deleteFile(f); else f.delete(); } dir.delete(); } }