By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,964 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,964 IT Pros & Developers. It's quick & easy.

Limit to File.deleteOnExit() ?

P: n/a
I have to go through and delete a bunch of files after another program used
them. I'm doing:

File oFile = new File(fileName);
oFile.delete();
if (oFile.exists()) {
oFile.deleteOnExit();
}

Is there a limit to how many files I can have queued up to delete on exit?
Is this the same as having an open file? And should I wait, after deleting
(maybe a sleep call) before checking to see if it's still there before
issuing a deleteOnExit()?

Thanks!

Hal
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Liz
I have used deleteonexit to delete a few hundred files
with no problems.

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:DYgfc.37055$wP1.139741@attbi_s54...
I have to go through and delete a bunch of files after another program used them. I'm doing:

File oFile = new File(fileName);
oFile.delete();
if (oFile.exists()) {
oFile.deleteOnExit();
}

Is there a limit to how many files I can have queued up to delete on exit?
Is this the same as having an open file? And should I wait, after deleting (maybe a sleep call) before checking to see if it's still there before
issuing a deleteOnExit()?

Thanks!

Hal

Jul 17 '05 #2

P: n/a
Hal Vaughan wrote:
I have to go through and delete a bunch of files after another program used
them. I'm doing:

File oFile = new File(fileName);
oFile.delete();
if (oFile.exists()) {
oFile.deleteOnExit();
}

Is there a limit to how many files I can have queued up to delete on exit?
Is this the same as having an open file? And should I wait, after deleting
(maybe a sleep call) before checking to see if it's still there before
issuing a deleteOnExit()?


You are relying on the JVM being shut down gracefully. If it's just
killed the "deleteOnExit" won't have a chance to work. I'm also
wondering what makes you think deleteOnExit will work if for some reason
delete() didn't.....

David Rolfe
Orinda Software
Dublin, Ireland

www.orindasoft.com

Jul 17 '05 #3

P: n/a
D Rolfe wrote:
Hal Vaughan wrote:
I have to go through and delete a bunch of files after another program
used
them. I'm doing:

File oFile = new File(fileName);
oFile.delete();
if (oFile.exists()) {
oFile.deleteOnExit();
}

Is there a limit to how many files I can have queued up to delete on
exit?
Is this the same as having an open file? And should I wait, after
deleting (maybe a sleep call) before checking to see if it's still there
before issuing a deleteOnExit()?

You are relying on the JVM being shut down gracefully. If it's just
killed the "deleteOnExit" won't have a chance to work. I'm also
wondering what makes you think deleteOnExit will work if for some reason
delete() didn't.....


I've seen it happen quite often that I try to delete a file and it doesn't
delete. I've tested the above snippet a number of times and I've found
MANY cases where Java wouldn't delete the file on the first delete, but
would on deleteOnExit(). I don't know why. In this case, I open the file,
read it all into a byte[] array, close the file, do other stuff with the
data (like dump it into a string), then delete it. I don't know why (I'm
self taught, so maybe I'm missing something here), but it's possible the
jvm hasn't released it's hold on the file from when I read from it, so it's
not able to delete it yet.
David Rolfe
Orinda Software
Dublin, Ireland

www.orindasoft.com


Jul 17 '05 #4

P: n/a
Liz

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:dNhfc.142454$K91.355915@attbi_s02...
D Rolfe wrote:
Hal Vaughan wrote:
I have to go through and delete a bunch of files after another program
used
them. I'm doing:

File oFile = new File(fileName);
oFile.delete();
if (oFile.exists()) {
oFile.deleteOnExit();
}

Is there a limit to how many files I can have queued up to delete on
exit?
Is this the same as having an open file? And should I wait, after
deleting (maybe a sleep call) before checking to see if it's still there before issuing a deleteOnExit()?

You are relying on the JVM being shut down gracefully. If it's just
killed the "deleteOnExit" won't have a chance to work. I'm also
wondering what makes you think deleteOnExit will work if for some reason
delete() didn't.....


I've seen it happen quite often that I try to delete a file and it doesn't
delete. I've tested the above snippet a number of times and I've found
MANY cases where Java wouldn't delete the file on the first delete, but
would on deleteOnExit(). I don't know why. In this case, I open the

file, read it all into a byte[] array, close the file, do other stuff with the
data (like dump it into a string), then delete it. I don't know why (I'm
self taught, so maybe I'm missing something here), but it's possible the
jvm hasn't released it's hold on the file from when I read from it, so it's not able to delete it yet.
I also have experience with delete not working, but deleteonexit does work.
In my case, I read the directory and open all jpg files as images to get the
width and height, then I delete the small ones.
David Rolfe
Orinda Software
Dublin, Ireland

www.orindasoft.com

Jul 17 '05 #5

P: n/a


Hal Vaughan wrote:

I've seen it happen quite often that I try to delete a file and it doesn't
delete. I've tested the above snippet a number of times and I've found
MANY cases where Java wouldn't delete the file on the first delete, but
would on deleteOnExit(). I don't know why. In this case, I open the file,
read it all into a byte[] array, close the file, do other stuff with the
data (like dump it into a string), then delete it. I don't know why (I'm
self taught, so maybe I'm missing something here), but it's possible the
jvm hasn't released it's hold on the file from when I read from it, so it's
not able to delete it yet.


Now I come to think of it I've seen this as well. I have a piece of code
that calls deleteOnExit but also have a routine that checks for 'stale'
files when the application is started (based on file extension and
location) and deletes them in case delete/deleteOnExit didn't work the
previous time.

David Rolfe

-------------------------------------------------------------------------------
Remove FRUITBAT for a valid Email address..

Orinda Software make "OrindaBuild", which generates Java JDBC access
code for calling PL/SQL procedures. www.orindasoft.com

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.