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 »


Comment from: Tony [Visitor]

Thanks 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]

Thanks a lot for the information. This problem was driving me mad.

20/10/10 @ 12:58
Comment from: MrKnödelmann [Visitor]  

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) {}
try {
} catch (InterruptedException e) {



14/02/11 @ 15:42
Comment from: Fern [Visitor]

Excellent, 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]

Perfecto!!! ahora entiendo porque no podia hacer el rename.
Thanks a bunch!!

23/04/12 @ 18:44
Comment from: SR [Visitor]

Hi, 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: davidnewcomb [Member]  

Check 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]  

File o=new File("d:/old.txt");
File n=new File("d:/new.txt");

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]

thanks a lot … it really saved the day for me once again thanks:)

31/10/12 @ 08:37
Comment from: Terrance [Visitor]  

I am working with over 4000 pdfs that I want to sort by size into two separate folders, landscape and portrait folders. I wrote the code to get that done but I am having the same problem with the result that the files are not being renamed to the folders. However, I have to get the pagesize for each pdf file and then move it to the landscape folder or portrait folder depending if height>width. how do I close the inputstream without touching the file and expect the result?

24/07/15 @ 12:57
Comment from: davidnewcomb [Member]  

I would open the file, find out what you want, close the file then move it to the correct folder.

04/08/15 @ 14:48

Leave a comment

Your email address will not be revealed on this site.

Your URL will be displayed.
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)