Here you can find the source of deleteFiles(File folder)
public static boolean deleteFiles(File folder)
//package com.java2s; /*/* w w w . j av a 2s . co m*/ * Copyright @ 2006-2010 by The Jxva Framework Foundation * * 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.File; import java.util.LinkedList; import java.util.List; public class Main { private static final String FILE = "file"; private static final String FOLDER = "folder"; private static final String ALL = "all"; public static boolean deleteFiles(File folder) { if (folder == null) return false; if (!folder.exists() || !folder.isDirectory()) { return false; } for (File file : getFiles(folder)) { file.delete(); } return true; } public static List<File> getFiles(File folder) { return getAll(folder, FILE); } public static List<File> getAll(File folder) { return getAll(folder, ALL); } private static List<File> getAll(File folder, String type) { List<File> list = new LinkedList<File>(); File flist[] = folder.listFiles(); for (int i = 0; i < flist.length; i++) { if (type.equals(FILE)) { if (!flist[i].isDirectory()) { list.add(flist[i]); } } else if (type.equals(FOLDER)) { if (!flist[i].isDirectory()) { list.add(flist[i]); } } else { list.add(flist[i]); } } return list; } }