Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops, I forgot the link.
thread on SCJD
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic