Here you can find the source of deleteFilesRecursive(File src)
Parameter | Description |
---|---|
src | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void deleteFilesRecursive(File src) throws IOException
//package com.java2s; import java.io.*; public class Main { /**//from w w w . j av a 2s .c o m * delete all the files in a directory recursively * * @param src * @throws IOException */ public static void deleteFilesRecursive(File src) throws IOException { // Check to ensure that the source is valid... if (!src.exists()) { if (!src.mkdirs()) { throw new IOException( "deleteFiles: Could not create direcotry: " + src.getAbsolutePath() + "."); } } else if (!src.canRead()) { // check to ensure we have rights to the source... throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath() + "."); } // is this a directory copy? if (src.isDirectory()) { // get a listing of files... String list[] = src.list(); // copy all the files in the list. for (int i = 0; i < list.length; i++) { File src1 = new File(src, list[i]); deleteFilesRecursive(src1); } } else { src.delete(); } } }