0

I'm trying to copy a folder full of .txt and .jpg files into a separate folder.

From: C:/Folder/resources/

To: C:/Folder/backup/resources

public void backup() throws IOException
{
    FileUtils.copyDirectory(new File(SOURCE), new File(DESTINATION));
}

Upon calling the method, everything gets copied over, but I get a FileNotFoundException for desktop.ini and thumbs.db, it switches between the two. Using the apache.commons.io and I was wondering if anyone can point me in the right direction on how to solve the Exception. Since everything is copied over, should I just put it in a try catch block and move on or is there a solution? The SOURCE = the from path and the DESTINATION = the to path. Should they not be new Files?

java.io.FileNotFoundException: C:\Folder\resources\desktop.ini (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1069)
at org.apache.commons.io.FileUtils.doCopyDirectory(FileUtils.java:1358)
at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:1319)
at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:1191)
at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:1160)

Thanks!

atkHOBO
  • 83
  • 1
  • 1
  • 4
  • im guessing the files are simply in use. have you tried using something lik unlocker to see if theyre being used by some other application, like explorer.exe? – radai Aug 27 '13 at 18:07
  • They are in use, I have the whole thing running as a GUI with the option of a back/restore button and they use the files. So, I should probably have it quit what it's doing and then try it? – atkHOBO Aug 27 '13 at 18:10
  • surround it in a try/catch and skip those files. not much else you can do, as calling into win32 api to unlock them would be complicated – radai Aug 27 '13 at 18:12
  • Ok, sorry one last question, I assume I can't tell it to skip those files, so just use a try { backup() } catch(Exception e) {} and then keep going? Since I don't really need those files for it to work. Thank you. – atkHOBO Aug 27 '13 at 18:16
  • i was thinking more along the lines of a try/catch block inside backup(), around each and every file - you must iterate over all files somehow anyway. otherwise you might constantly miss whatever files come "after" the locked ones. – radai Aug 27 '13 at 18:18
  • I let the copyDirectory method iterate through everything, but I'll try to do something along those lines, thanks for the idea. – atkHOBO Aug 27 '13 at 18:22

0 Answers0