Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot move a file from one directory to other.  RSS feed

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using some profiler, i.e. JProfiler, to know if there is any unclosed stream.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
: ( 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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nevermind another one my sleepy head codes...., problem solved -

I was doing the following foolish thingy -


[/code]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!