Educating the world

Our blog has over 10,000 readers a month

« Simple way of sharing files on a home networkAutomatically showing the Editor's file in Eclipse's Package Explorer »

9 comments

Comment from: Tony [Visitor]
TonyThanks for this!!! I was having the exact same problem with the delete always returning false for what seemed like no good reason. Behold - the FileInputStream was still open from reading the properties file!
22/07/10 @ 19:39
Comment from: Soner [Visitor]
SonerThanks a lot for the information. This problem was driving me mad.
20/10/10 @ 12:58
Comment from: MrKnödelmann [Visitor] Email
MrKnödelmannhttp://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213298

I had the same problem with writing data to a new file and than try to renam it.
This worked for me:
try {
fos.close(); // fos is a FileOutputStream
} catch (Exception e) {}
System.gc();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}

hth

Regards
14/02/11 @ 15:42
Comment from: Fern [Visitor]
FernExcellent, because I'm having this problem right now.. I'm glad I found this.. woohoo..
Thanks a bunch..
22/07/11 @ 22:13
Comment from: L3x1uTh0r [Visitor]
L3x1uTh0rPerfecto!!! ahora entiendo porque no podia hacer el rename.
Thanks a bunch!!
23/04/12 @ 18:44
Comment from: SR [Visitor]
SRHi, I am trying to rename the sub folders in about 10 parent folders in the loop. Meanwhile I am uploading the files in to the sub folders and downloading the files, but closing the files. But rename fails some times for 1 or two sub folders randomly if I continuously doing uploading, renaming and downloading. How to solve this problem?
31/05/12 @ 08:59
Comment from: David Newcomb [Member] Email
David NewcombCheck that you are closing after an exception.
Check that you are not trying to rename a folder while you are touching any of the files contained within it. Under Unix this will be fine but windows is useless and won't let you alter parents of filesystem entities.
06/06/12 @ 09:15
Comment from: Selvadurai [Visitor] Email
SelvaduraiFile o=new File("d:/old.txt");
File n=new File("d:/new.txt");
n.delete();
o.renameTo(n);

n.delete() : We need to delete the file(new.txt) if exists.

o.rename(n) : so that the file(old.txt) is renamed as new.txt
11/10/12 @ 19:58
Comment from: Sathiya [Visitor]
Sathiyathanks a lot ... it really saved the day for me once again thanks:)
31/10/12 @ 08:37

Leave a comment


Your email address will not be revealed on this site.
(Line breaks become <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)