Deleting files using java
<pre><code>    import java.io.*;

public class FileChecker {

   private static final String FILE_DIR = "F:/study/";
   private static final String FILE_TEXT_EXT1 = ".pdb";
   private static final String FILE_TEXT_EXT2 = ".ali";
   private static final String FILE_TEXT_EXT3 = ".txt";
   private static final String FILE_TEXT_EXT4 = ".py";
   private static final String FILE_TEXT_PREFIX1 = "target.";
   private static final String FILE_TEXT_PREFIX2 = "blastOutput.";
   //private static final String FILE_TEXT_PREFIX3 = "1OPL.";

  //public static void main(String args[]) 
   public FileChecker()
   {
/*new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT1);
        new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT2);
        new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT3);
       new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT4);
      new FileChecker().deleteFile2(FILE_DIR,FILE_TEXT_PREFIX1);
        new FileChecker().deleteFile2(FILE_DIR,FILE_TEXT_PREFIX2);
        new FileChecker().deleteFile2(FILE_DIR,FILE_TEXT_PREFIX3);*/
   }

   public void deleteFile(String folder, String ext){

     GenericExtFilter filter = new GenericExtFilter(ext);
     File dir = new File(folder);

     //list out all the file name with .txt extension
     String[] list = dir.list(filter);

     if (list.length == 0) return;

     File fileDelete;

     for (String file : list){
    String temp = new StringBuffer(FILE_DIR).append(File.separator).append(file).toString();
        fileDelete = new File(temp);
        boolean isdeleted = fileDelete.delete();
        System.out.println("file : " + temp + " is deleted : " + isdeleted);
     }
   }
 public class GenericExtFilter implements FilenameFilter {

       private String ext;

       public GenericExtFilter(String ext) {
         this.ext = ext;             
       }

       public boolean accept(File dir, String name) {
         return (name.endsWith(ext));
       }
    }

 public void deleteFile2(String folder, String prefix){

     GenericExt filter = new GenericExt(prefix);
     File dir = new File(folder);

     //list out all the file name with .txt extension
     String[] list = dir.list(filter);

     if (list.length == 0) return;

     File fileDelete;

     for (String file : list){
    String temp = new StringBuffer(FILE_DIR).append(File.separator).append(file).toString();
        fileDelete = new File(temp);
        boolean isdeleted = fileDelete.delete();
        System.out.println("file : " + temp + " is deleted : " + isdeleted);
     }
   }
 public class GenericExt implements FilenameFilter {

       private String prefix;

       public GenericExt(String prefix) {
         this.prefix = prefix;             
       }

       public boolean accept(File dir, String name) {
         return (name.startsWith(prefix));
       }
    }  

 public void deleteFile3(String ID, String Chain)
 {
     File file = new File(ID+".pdb");
     if(file.delete())
     {
     System.out.println(ID+"deleted");
     }
     File file2 = new File(Chain+".pdb");
     if(file2.delete())
     {
      System.out.println(Chain+"deleted");
     }

 }


}
</code></pre>

<p>This code is invoked from another class. When run in continuation as several of my codes should be.. it does not delete two pdb files specifically when i try to delete my files of a specific file extension.  I tried closing then them too using file.close() and then deleting them again when the entire file name and extension is know but again to no avail.</p>

<pre><code>    String FILE_DIR = "F:/study";
    String FILE_TEXT_EXT1 = ".pdb";
  String FILE_TEXT_EXT2 = ".ali";
  String FILE_TEXT_EXT3 = ".txt";
  String FILE_TEXT_EXT4 = ".py";
    String FILE_TEXT_PREFIX1 = "target.";
  String FILE_TEXT_PREFIX2 = "blastOutput.";
 //  String FILE_TEXT_PREFIX3 = "1OPL.";


new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT1);
        new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT2);
        new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT3);
       new FileChecker().deleteFile(FILE_DIR,FILE_TEXT_EXT4);
      new FileChecker().deleteFile2(FILE_DIR,FILE_TEXT_PREFIX1);
        new FileChecker().deleteFile2(FILE_DIR,FILE_TEXT_PREFIX2);
   // new FileChecker().deleteFile2(FILE_DIR,FILE_TEXT_PREFIX3);
        BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_DIR+TemplatePDBID+".pdb", true));
    bw.close();
    BufferedWriter bw1 = new BufferedWriter(new FileWriter(FILE_DIR+Template+".pdb", true));
    bw1.close();
    new FileChecker().deleteFile3((FILE_DIR+TemplatePDBID), (FILE_DIR+Template));
</code></pre>

<p>This is the snippet of the other class which invokes my FileChecker class at the end.</p>

<p>I'm pasting the out I received</p>

<pre><code>file : F:/study\1OPL.pdb is deleted : false
file : F:/study\1OPL_A.pdb is deleted : false
file : F:/study\model.pdb is deleted : true
file : F:/study\alignment.ali is deleted : true
file : F:/study\tempAli.ali is deleted : true
file : F:/study\1OPL.fasta.txt is deleted : true
file : F:/study\ModelDescription.txt is deleted : true
file : F:/study\ModellerOutput.txt is deleted : true
file : F:/study\script.py is deleted : true
file : F:/study\target.D00000001 is deleted : true
file : F:/study\target.ini is deleted : true
file : F:/study\target.rsr is deleted : true
file : F:/study\target.sch is deleted : true
file : F:/study\target.V99990001 is deleted : true
file : F:/study\blastOutput.xml is deleted : true
</code></pre>

<p>please help me with this anomaly.. I am unable to understand why exactly it is skipping the 1st two files in all instances.</p>
