473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Limit to File.deleteOnExit() ?

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
5 8941
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
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
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
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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil... | last post by:
I have a directory with a lot of jpg files. I want to delete the small ones. Small means less than 100 pixels by 100 pixels. I use File.list() to get the list of files. I use ImageIcon(filename)...
10
by: Randell D. | last post by:
Folks, I have a SELECT that returns with multiple records - It works when I have a LIMIT clause but when I try to include a GROUP BY clause, the select returns nothing (ie no records, no...
2
by: steve | last post by:
I am setting up a huge database in mysql, and I get the above error in Linux. I believe it is related to the size of one of my tables, which is 4,294,966,772 bytes in size. Can someone help. How...
6
by: Hannu | last post by:
Hi. In the ldb file you can see the users of the mdb-file. If you open the mdb-file your machine and username will be written in the lbd- file. Allthough you close the mdb-file your name won't...
8
by: Peter Ballard | last post by:
Hi all, I've got a C program which outputs all its data using a statement of the form: putchar(ch, outfile); This has worked fine for years until it had to output more than 2GB of data...
10
by: VM | last post by:
How can I limit the use of the PC's virtual memory? I'm running a process that basically takes a txt file and loads it to a datatable. The problem is that the file is over 400,000 lines long (77...
5
by: Jefferis NoSpamme | last post by:
Hi all, I'm trying to limit the file size of an image submission and I keep running into various problems. I've got most of it working, but I'm stumped and I have a basic question as to WHY this...
9
by: eastcoastguyz | last post by:
I wrote a simple program to continue to create a very large file (on purpose), and even though there is plenty of disk space on that device the program aborted with the error message "File Size...
6
by: howa | last post by:
Suppose the file is stored in "upload_tmp_dir ", so why I need to increase the memory limit? If I want to upload 100 MB, how large should I set? Thanks.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.