Here you can find the source of deleteFileCascade(String directory)
Parameter | Description |
---|---|
directory | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void deleteFileCascade(String directory) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class Main { /**/*from ww w . ja v a 2s. co m*/ * Delete a folder with all the sub files. * @param directory * @throws IOException */ public static void deleteFileCascade(String directory) throws IOException { deleteFileCascade(new File(directory)); } /** * Delete a folder with all the sub files. * @param directory * @throws IOException */ public static void deleteFileCascade(File directory) throws IOException { // delete all the sub files recursively if (directory.isDirectory()) { File[] files = directory.listFiles(); // some JVM return null for listfiles if (files == null) return; for (File file : files) { file.setWritable(true); deleteFileCascade(file); } } Files.delete(Paths.get(directory.getAbsolutePath())); // delete the directory //if ( !directory.delete() ) // throw new FileNotFoundException( "Failed to delete file: " + directory ); } }