Following class provides a way to delete files with a given extension.

Java Code:
public class DelFile {
   public static void main (String args[]) {
     System.out.println("hello");
     DelFile td = new DelFile();
     td.deleteFiles("c:/test/", ".gif");
    }

   public void deleteFiles( String d, String e ) {
     ExtensionFilter filter = new ExtensionFilter(e);
     File dir = new File(d);

     String[] list = dir.list(filter);
     File file;
     if (list.length == 0) return;

     for (int i = 0; i < list.length; i++) {
       file = new File(d + list[i]);
       boolean isdeleted =   file.delete();
       System.out.print(file);
       System.out.println( "  deleted " + isdeleted);
       }
     }

   class ExtensionFilter implements FilenameFilter {
     private String extension;
     public ExtensionFilter( String extension ) {
       this.extension = extension;             
       }
     public boolean accept(File dir, String name) {
       return (name.endsWith(extension));
       }
     }
}