title: File.delete() fails to delete files in a directory
body: <p>After writing the text files into a directory, i am trying to delete the empty files written by the PrintWriter.</p>
  
  <p>File.delete() function fails to delete the file. Below is the code for writing and deleting.</p>
  
  <pre><code>private static void writeFile(ArrayList&lt;ArrayList&lt;String&gt;&gt; listRowVal, String szOutputDir, ArrayList&lt;String&gt; listHeader){     
         PrintWriter pw  = null;         
         try {                    
             ArrayList&lt;String&gt; listCells = listRowVal.get(0);            
             int iCells = listCells.size();          
             for(int k=0; k&lt;iCells; k++){
                 String language = listHeader.get(k);
                 String szFileName = "files_"+ language +".csv";                 
                 pw  = new PrintWriter(new FileWriter(szOutputDir + File.separator + szFileName));               
                 for(ArrayList&lt;String&gt; listNCRCellVal : listRowVal){
                     String szVal = listNCRCellVal.get(k);
                     if(szVal != null &amp;&amp; szVal.trim().length() &gt; 0){
                         pw.println(szVal);
                     }
                     pw.flush();                
                 }                   
             }           
  
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }finally {
          try {
              if(pw != null){
               pw.close();
               pw = null;
              }
              //System.gc();
              deleteEmptyFiles(szOutputDir);
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  
     }
   private static void deleteEmptyFiles(String szDirPath) {
          File file = new File(szDirPath);
          if (file.isDirectory()) {
              String[] files = file.list();
              if (files.length &gt; 0) {
                  for (String szFileName : files) {
                      File deleteFile = new File(szDirPath + File.separator + szFileName);
                      if (deleteFile.length() == 0) {                     
                          //deleteFile.setWritable(true, false);
                          boolean bdeleted = deleteFile.delete();                     
                          if(bdeleted){
                              System.out.println(deleteFile.getName() + " deleted.");                         
                          }
                      }
  
                  }
              }
          }
      }
  </code></pre>
  
  <p>What is going wrong..??</p>