Here is my code: if(fileToDelete != null) { boolean deleted = fileToDelete.delete(); System.out.println(deleted); } It always returns false. The file does exist, my .java.policy file does allow deleting of files. Yet the file does not get deleted. Any clue as to what this File newbie could be missing?
of what I can tell you.. I have not run into such a problem before. It is only when I am trying to delete a file which is locked with me holding its outputStream, I get the false problem. I also encounter an AccessDenied Exception. Tell me if you are running the code segment on an Applet. lupo
"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
The most common problem is what gautham said - if there's an InputStream or OutputStream attached to the file which has not been closed, the delete() may fail. Make sure that you close() any attached streams first. (Use the a finally{} clause to ensure this happens even if exceptions are thrown.) Another possible reason for delete() to fail is that the file may not exist (under the name you've given). Try: System.out.println(fileToDelete.getAbsolutePath()); System.out.println("fileToDelete.exists() ? "exists" : "doesn't exist")); for more info. (The absolute path tells you where the system is really looking for the file - sometimes it's not where you think.)