Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileUtils.copyFile fails for large files

I have a simple Java app that is trying to copy a file across the WAN (from Ireland to NY).

I recently modified it to use FileUtils because the native Java file copy was too slow. I researched and found that because Fileutils uses NIO it is better. The file copy now works great but occasionally I need to copy very large files (> 200Mb) and the copy fails with the error:

java.io.IOException: Failed to copy full contents from...

I know the error means that the destination file size is not the same as the source, so initially I figured it was network problems. The process tries repeatedly to copy the file every couple of hours but it is never successful. However, when I copy the file manually through a Windows exploer then it works fine. This would seem to rule out the network...but I'm not really sure.

I have searched but could not find any posts with the exact same issue. Any help would be greatly appreciated.

Thanks!

Addition:
I am using this FileUtils method:

public static void copyFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOException
like image 355
Tony Avatar asked Aug 27 '13 13:08

Tony


1 Answers

So I found the issue to be on the destination folder. There is a polling process that is suppose to pick up the file after it gets copied. However, the file was getting moved prior to the copy being completed. This probably wouldn't happen on a windows drive because the file would be locked (i tested locally and i could not delete while file is copying). However, the destination folder is a mounted a celerra share. The unix process under the hood is what grabs the file...I guess it doesn't care if some windows process is still writing to it.

Thanks for your time medPhys-pl!

like image 156
Tony Avatar answered Sep 30 '22 14:09

Tony