Here you can find the source of deleteFiles(File parent, boolean incParent)
Parameter | Description |
---|---|
parent | file to delete. If this is a directory then any children are deleted. |
incParent | boolean that determines if the parent file is also deleted. |
Parameter | Description |
---|
public static void deleteFiles(File parent, boolean incParent) throws FileNotFoundException
//package com.java2s; /*/*from w w w . j a v a2 s . co m*/ * Copyright 2004 - 2012 Cardiff University. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.*; public class Main { /** * deletes files recursively. can optionally delete the parent file as well. So, if the parent file * is not a directory, and incParent is false, then nothing will be deleted. * * @param parent file to delete. If this is a directory then any children are deleted. * @param incParent boolean that determines if the parent file is also deleted. * @throws java.io.FileNotFoundException */ public static void deleteFiles(File parent, boolean incParent) throws FileNotFoundException { if (!parent.exists()) { throw new FileNotFoundException("File does not exist."); } if (parent.isDirectory() && !(parent.listFiles() == null)) { File[] files = parent.listFiles(); for (int i = 0; i < files.length; i++) { deleteFiles(files[i], true); } } if (incParent) { parent.delete(); } } }