I had a similar problem in an example case I created. Basically, I create a File object (oFile) associated with a non-existent file (file1.txt). oFile.exists() returns FALSE as it should. I then create a separate FileWriter object (oFileWriter) associated with the same non-existent file (file1.txt). After the FileWriter is constructed, oFile.exists() returns TRUE (again, as expected). I then attempt to delete the file using oFile.delete(), which consistently returns FALSE. However, oFile.isDirectory(), oFile.isFile(), oFile.getPath(), oFile.getName(), and oFile.toString() all return values correct for the existing file. (I manually delete file1.txt between
test runs. ) It finally hit me that file1.txt would remain busy until I executed oFileWriter.close(). When I execute oFileWriter.close() before executing oFile.delete(), the deletion succeeds.
So now my question is, IS THERE A WAY TO DETERMINE IF A FILE IS BUSY?