aspose file tools*
The moose likes I/O and Streams and the fly likes exception after ApacheCommons FileUtils.moveFile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "exception after ApacheCommons FileUtils.moveFile" Watch "exception after ApacheCommons FileUtils.moveFile" New topic
Author

exception after ApacheCommons FileUtils.moveFile

Lawrence Gatson
Greenhorn

Joined: Oct 25, 2010
Posts: 9
Hello,

I am using ApacheCommons "FileUtils.moveFile (<file>, <file>) to move an XML file to a destination directory...

The call to "MOVE" seems to be working; however for each call to move the file I'm getting an IOException thrown with the following message...

Failed to delete original file 'C:\Temp\sourceDir\print\<filename>' after copy to 'C:\TEMP\destinationPolicy\<filename>

Does anybody have any idea why this is happening and how to prevent the exception?

Thanks
lg
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

The most common cause of such a problem is that you have the file open somewhere else in the code, which prevents it from being deleted.


[How To Ask Questions On JavaRanch]
Lawrence Gatson
Greenhorn

Joined: Oct 25, 2010
Posts: 9
Interesting, however nowhere in the code do I explicitly call file.open().

However, before the call to "move", I need to parse the XML file to determine the correct destination; I do this by creating a DOM object to read the needed data.

Could this DOM object be holding on to the files somehow? I'm not aware of a need to "close" a DOM object, should I? Also, the move call is working, it copies the file to the destination directory AND removes it from the source directory. Unfortunately it also throws the IOException.

Some additional info...my code runs inside of a thread that wakes up every TBD seconds (currently set to 20), reads the contents of a source directory and moves all files to different destination directories. I don't see how this could be causing the IOException.

Thanks for your response.

lg
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Lawrence Gatson wrote:
Could this DOM object be holding on to the files somehow?


That sounds suspicious. What DOM API are you using?
Lawrence Gatson
Greenhorn

Joined: Oct 25, 2010
Posts: 9
not sure, how can i tell?

I'm using Java 1.6, my import list is:

import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception after ApacheCommons FileUtils.moveFile