1

I am trying to download the file to local disk from the URL. So I'm trying to use the

FileUtils.copyURLToFile(new URL(url), filename);

But I get IOException Occurred java.io.EOFException: End of input or Premature EOF often without complete download of file. Please let me know what's wrong in this line. What can I check before writing this file?

Jonik
  • 80,077
  • 70
  • 264
  • 372
user3161879
  • 103
  • 1
  • 17
  • Have you tried [this](http://stackoverflow.com/questions/19059244/how-to-use-fileutils-io-correctly) or with another URL and local file? – xav Jan 29 '14 at 22:41

1 Answers1

0

The download was incomplete. There's nothing you can check beforehand, obviously. If this happens you should probably delete the target file.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 2
    I don't know why this answer was downvoted, but it seems like the right answer to me. It could perhaps be improved with a link to the documentation, which mentions that IOException will be thrown "if an IO error occurs during copying": http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#copyURLToFile(java.net.URL, java.io.File) – David Conrad Jan 29 '14 at 22:44
  • @DavidConrad Thanks. A link to EOFException might have been more appropriate, but the OP seems to know what it is. Re the downvote, maybe someone thinks it is possible to foretell an incomplete download? :-) – user207421 Jan 29 '14 at 23:18
  • Can someone let me know how to resolve this issue? The link which iam using seems to be correct and its happening all the time at copyURLToFile line. – user3161879 Feb 11 '14 at 20:26
  • Can you download the file with a browser? – user207421 Feb 11 '14 at 22:03