wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Cannot move a file from one directory to other. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Cannot move a file from one directory to other." Watch "Cannot move a file from one directory to other." New topic
Author

Cannot move a file from one directory to other.

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Hi All, This might seem a very old problem, but I have searched a lot for this and I think I know the problem but I want some clarification for the workarounds that I am planning to implement for this problem --

My problem:
There are four folders A, B, C, D. I am getting a file in folder A, moving it to folder B for processing, now in folder B I am encrypting that file and creating a file in folder C with the same name (need a backup in B), and then as soon my encryption is complete I move the file from C to D(my output).

I think the problem is with my encryption process and I am leaving some file streams open. Is there any way I can check this? if I am leaving any streams open? any tool, any ideas will help

I have checked each and every line of code and closed all the streams that I could see - I am also checking if the file is writable or not before moving, I am also retrying the moving logic for some time untill it fails....

So finally I am doing this - Copying the file from C to D and then deleting the file in 'C'(but it fails), I want to know from you guys if I am doing the right thingy?? Can I get a safe result or a valid file always if I copy a file with hanging streams.. ??? please help

Thanks in advance ! Regards


Time is what we want the most, but what we use the worst. -- William Penn
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
How about using some profiler, i.e. JProfiler, to know if there is any unclosed stream.
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

: ( I cant use a profiler and I cant share the code : (

FYI - I am using Bouncycastle for encryption.

debugging some more I found out that inbuilt streams in the bouncy library like ArmoredOutputStream, BCPGOutputStream they dont close the underlying streams and etc.... I tried to assign all the streams to null just after closing them in my finally statement...

Should Assigning the stream objects to null take care of freeing the streams ?? because when I tried this the file didn't move : ( please advice.. urgent..!!!
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

nevermind another one my sleepy head codes...., problem solved -

I was doing the following foolish thingy -


[/code]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot move a file from one directory to other.
 
Similar Threads
File download - Different behaviour of Windows & Linux server
How do i set a/the classpath.
Hard to configurate Hibernate using NetBeans 5.5.1
Efficient way to download an image
newbie ... few questions for getting started