Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes A question about File.delete() on different platforms. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "A question about File.delete() on different platforms." Watch "A question about File.delete() on different platforms." New topic
Author

A question about File.delete() on different platforms.

Joe J. Wang
Ranch Hand

Joined: Feb 26, 2003
Posts: 67
Hi there,
I met a problem when I am doing the SCJD assignment. What I am trying to do is to delete a .properties file located in the current folder when some fatal error occured. But the code can only work(delete the .properties file) on linux, can't work on windows(2000/xp). Here is the code.

Before the code above, there is a FileInputStream and a FileOutputStream access the file. But I did close them and assign null to the Streams before I delete the file. I am really not sure what could be the problem. Why it works on linux(RH7.2 and RH9) but not on windows?
Can somebody give me some hints? Any inputs is appreciated!
Thanks,
Joe
PS: here is the link to the original thread in the SCJD forum. If I violate any rules here, please forgive me, I really need to solve the problem. Thanks!


SCJP, SCJD, SCWCD, SCEA I.
Joe J. Wang
Ranch Hand

Joined: Feb 26, 2003
Posts: 67
oops, I forgot the link.
thread on SCJD
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Are you really sure that you closed the streams? Since the code you show is in a catch block, it seems possible that the exception was thrown before the close() was called. Try putting a print statement next to the close() to see if it's really being called. Best practice here is to put the close() in a finally {} block to guarantee it gets called, regardless of what else may happen:

As shown above, you might also look at the file permissions of the file you're trying to delete. Hope that helps...


"I'm not back." - Bill Harding, Twister
Joe J. Wang
Ranch Hand

Joined: Feb 26, 2003
Posts: 67
Haha, Jim, really need to thank you! Yeah, it is my stupid/careless. The exception happened before the close() operation.
But it is interesting that on linux it need not to close the streams.
Thank you very much!
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Catapultam habeo.
Engine of war for throwing arrows I have.
Nisi pecuniam omnem mihi dabis,
If not/Unless, money all, to me, you will give
ad caput tuum saxum immane mittam.
to head your, stone/fragment of rock immense, we will send/throw
-- Iacomus Iuvencissimus
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A question about File.delete() on different platforms.
 
Similar Threads
Having problems reading a file from servlet in Windows XP with Tomcat
Illegal access: this web application instance has been stopped already.
Junit problem, how to load a properties file
Opening HTML file from a desktop application
URLyBird1.3.2 A question about Exception handling of some "fatal" errors.