title: buffered reader and file.delete
body: <p>I'm creating a mini program that deletes Files using the File.delete() method but I'm having a little bit of an issue if I use the buffered Reader to read the .txt file before I delete it, it doesn't delete the file. I did come up with a solution for it: I just close the buffered reader before I delete the file. however this doesn't make sense to me as to why this is happening can anyone explain this.</p>
  
  <pre><code>import java.io.*;
  import java.nio.file.Files;
  
  public class Purge {
  
      public static void main(String[] args) throws IOException {
          // TODO Auto-generated method stub
  
          String sample;
          boolean result = false;
  
  
          BufferedReader amg = new BufferedReader(new FileReader("C:/Users/Steven/Desktop/me.txt"));
          sample = amg.readLine();
          amg.close();// closes the buffered reader 
                  System.out.println("Haha I'm stille here: "+sample);
          File anesu = new File("C:/Users/Steven/Desktop/me.txt");
  
          if (anesu.exists()){
  
          try{result = anesu.delete();
  
          }catch( Exception x){
              System.out.println("Problem Deleting File"+x);
          }
          catch( Throwable e){
              System.out.println("Problem Deleting File Throwable"+e);
          }
  
          }else{
              System.out.println("No File ");
          }
          System.out.println("File has been deleted: "+result);
  
      }
  
  }
  </code></pre>