Here you can find the source of deleteFiles(String sDir, String sSearch)
public static void deleteFiles(String sDir, String sSearch) throws IOException
//package com.java2s; import java.io.*; public class Main { public static void deleteFiles(String sDir, String sSearch) throws IOException { File dir = new File(sDir).getCanonicalFile(); File[] files = dir.listFiles(); for (File f : files) { if (sSearch.equals("*")) { f.delete();//w ww . j av a 2 s .c om } else { String[] sHold = sSearch.split(","); for (String s : sHold) { if (s.indexOf("*.") >= 0) { if (f.getName().indexOf(s.substring(s.indexOf(".") + 1)) >= 1) { f.delete(); } } } } } } }