• Post Reply Bookmark Topic Watch Topic
  • New Topic

file deletion  RSS feed

 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm using pdfc api to compare 2 pdf files. After comparison want to delete those files. When I used delete() method its not deleting those files and returning false.
When my code is running i tried to remove those files manually but following error message given by windows
"the action cannot be completed because the file is open in java tm platform se binary"

I think pdfc api is not closing the stream properly thats why files are not getting deleted.

Is there any way to delete files if any other api is using the streams for that file ?
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you providing the streams to pdfc, or are you just providing Files objects or file names? If you're providing the streams, then it's up to you to close them - preferably in a finally block, or using Java 7's try-with-resources syntax.
 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not passing any stream to the api, just passing file object.
batchRunner.runComparison(file1,file2);

Above method is getting called from my code

below is main method


 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes waiting a little bit or forcing System.gc helps making the relevant objects finalized/closed.
 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried system.gc() also, waited for more than few minutes but files were still there.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling gc is a bad idea here. Better dig through the API specs of the classes you are using to find out if there methods that release the files e.g IResultHandler.finish

 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've checked the api but there is nothing for to release the resorces.
IResultHandler.finish used to tell the result handler that no more error messages to add in handler.
 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E Armitage wrote:Calling gc is a bad idea here.


It is good to learn that it is a bad idea.

There was a bug in the standard Java stuff (in the windows JVM) that made such hacking and working around necessary.
Maybe that bug went away with newer versions.
Fortunately I did not come across this bug, only read about it.
 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following response I received from indt pdfc guys

this problem is known and will be fixed in the next version of i-net PDFC which is currently slated for the end of this month. The problem is the usage of FileChannels in the parser, which are not instantly released by Java. the next version doesn't use this type of file access anymore
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figures. I suppose renameTo doesn't work as well? If it does work you could renameTo some directory and delete that directory on application shutdown as some kind of workaround.
 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E Armitage wrote:Figures. I suppose renameTo doesn't work as well?


Some OS/file systems pairs will let you rename or remove (delete) an open file (it is usually the case with Unices including Linux), others (Windows) won't.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!