I have been using a specific piece of code to delete files from a folder but it is proving very problematic because maybe I forgot to close an InputStream or two. The code I have is so big that I am not be able to see all the Inputstreams that I have not closed. Is there a way of deleting files whether there is an open InputStream or not?
This is the piece of the code that I have been using;
File fin = new File("C:/ABC Statements final/");
    File[] finlist = fin.listFiles();       
    for (int n = 0; n < finlist.length; n++) {
        if (finlist[n].isFile()) {
        System.gc();
        Thread.sleep(2000);
            finlist[n].delete();
        }
    }        
I have edited the code. This version works.
 
     
     
     
     
     
     
    