problem while trying to delete files

M

Marcin Rodzik

Hello everybody,
I experience a following problem: I try to delete files my code have
created using the File.delete() method, and if the delete operation
fails, I use File.deleteOnExit(); however, some files still persist to
exist.

I found an article: http://www.devx.com/Java/Article/22018 (I'm using
Windows XP, and I havn't tested my application on other systems).
Therefore, my hipothesis is that there are some open streams to these
files in my program.

The thing is I use someone else's code in my program, and can't really
figure out where these open streams are. My questions are:
+ how can I track down these open streams in a simple way?
+ can there be any other reasons why my files can't be deleted?

Thank you for any help and advice.

MR
 
A

Andreas Leitgeb

Marcin Rodzik said:
I experience a following problem: I try to delete files my code have
created using the File.delete() method, and if the delete operation
fails, I use File.deleteOnExit(); however, some files still persist to
exist.

Can you delete these files manually from explorer after your app is
finished? (If not, then it is obviously not Java's fault.)

Perhaps your app really crashed the jvm, so it didn't get to delete
those files? Just wild guessing.

Or perhaps you had spawned another process that kept the file busy
until shortly after the main app process finished.

Or perhaps your app has only closed all its windows, but the process
is still running and doing nothing... (E.g. if one forgets some boiler-
plate code to exit the process on window-close.)
 
M

Marcin Rodzik

Can you delete these files manually from explorer after your app is
finished? (If not, then it is obviously not Java's fault.)

Yes, I can.
Or perhaps you had spawned another process that kept the file busy
until shortly after the main app process finished.

On the contrary. When I used this files in the separate process
(launching another instance of the JVM) it was OK. Now, I reintegrated
different parts of code (mine and someone else's) and the problem
arose.

MR
 
A

Andreas Leitgeb

Marcin Rodzik said:
On the contrary. When I used this files in the separate process
(launching another instance of the JVM) it was OK. Now, I reintegrated
different parts of code (mine and someone else's) and the problem
arose.

Another thing you could try is create another file (one that you do *not*
open at all), and "deleteAtExit" that one, too. If that one then remains,
too, then you know, that deleteAtExit generally didn't work at exit. If the
other (non-opened) file *is* deleted, then you've at least focussed further
into the problem.

If that doesn't help, either, then I don't know other than suggest to undo
that integration work step-wise (or undo it completely and redo it step-wise),
until you find the culprit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top