Here you can find the source of deltree(String directory)
Parameter | Description |
---|---|
directory | a parameter |
public static void deltree(String directory)
//package com.java2s; import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { /**/*from www .ja v a 2 s .co m*/ * Recursive delete of a directory and all it's content * * @param directory */ public static void deltree(String directory) { deltree(new File(directory)); } /** * Recursive delete of a directory and all it's content * * @param directory */ public static void deltree(File directory) { if (directory.exists() && directory.isDirectory()) { File[] fileArray = directory.listFiles(); if (fileArray != null) { for (int i = 0; i < fileArray.length; i++) { if (fileArray[i].isDirectory()) { deltree(fileArray[i]); } else { fileArray[i].delete(); } } } directory.delete(); } } public static boolean exists(String fileName) { File file = new File(fileName); return file.exists(); } public static String[] listFiles(String fileName) { return listFiles(new File(fileName)); } public static String[] listFiles(File file) { List<String> files = new ArrayList<String>(); File[] fileArray = file.listFiles(); if (fileArray != null) { for (int i = 0; i < fileArray.length; i++) { if (fileArray[i].isFile()) { files.add(fileArray[i].getName()); } } } return (String[]) files.toArray(new String[0]); } }