Here you can find the source of deleteFiles(String dir)
public static boolean deleteFiles(String dir)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { public static boolean deleteFiles(String dir) { boolean success = false; File dirs = new File(dir); if (dirs.exists() && dirs.isDirectory()) { for (File f : dirs.listFiles()) { if (f.exists()) f.delete();//from w w w.j a va 2s.c om } success = true; } return success; } public static File[] listFiles(String path, String[] allowedExtension) { List<File> fs = getFiles(path, allowedExtension); return fs.toArray(new File[fs.size()]); } public static List<File> getFiles(String path, String[] allowedExtension) { List<File> r = new ArrayList<File>(); File rfolder = new File(path); if (rfolder.exists() && rfolder.isDirectory()) { File[] files = rfolder.listFiles(); for (File f : files) { if (isAllowedExtension(f.getName(), allowedExtension)) { r.add(f); } } } return r; } private static boolean isAllowedExtension(String fExt, String[] allowedExtension) { for (String ext : allowedExtension) { if (fExt.endsWith(ext)) return true; } return false; } }