title: How to delete a file from a directory using Java?
body: <p>Can anyone please tell me how to delete a file in a directory after being opened and loaded on to a database? </p>
  
  <p>Here is my code:</p>
  
  <pre><code>public static void main(String[] args) throws SQLException{
  
          int Count= 0;
  
          File directory = new File("C://Documents and Settings//welcome//My Documents//Bluetooth Exchange Folder");
          directory.deleteOnExit();
          File files[] = directory.listFiles();
  
          for(int index = 0; index &lt; files.length; index++){
  
              try {
  
                  FileReader inp = new FileReader (files[index]);
                  BufferedReader buf = new BufferedReader(inp);
                  String strLine;
  
                  try {
                      while ((strLine = buf.readLine()) != null)
                      {
                          System.out.println(strLine);
  
                          String[] dbColumnValues = strLine.split("%");
  
                          Connect.DoInsertIntoDB(Long.parseLong(dbColumnValues[0]),dbColumnValues[1],dbColumnValues[2], dbColumnValues[3]);
                          Count++;
                          System.out.println(Count + " Row(s) are inserted into the Database");
                          GenHTML.gen();
  
                      }
  
                  } 
  </code></pre>
  
  <p>But the files are not deleted in the directory.
  Please can anyone correct the mistake in my code?                   </p>
  
  <p>[Currently, I am testing with 3 files in the directory. After each file gets loaded to the datbase, I want each files to get deleted from the directory.]</p>
  
  <p>Thanks in advance!</p>