A_Elric A_Elric - 1 year ago 285
Java Question

Set timeout on org.apache.commons.io.FileUtils.copyURLToFile?

I have some code that copies using httpCore util copyURLtoFile() but I can't seem to find anything about timeouts in the documentation like I was able to with httpClient. The file it's pulling shouldn't pull out, but depending on that is.... interesting.

URL pjmUrl = new URL("myFile");
File projLoad = new File("projLoad.txt");
org.apache.commons.io.FileUtils.copyURLToFile(pjmUrl, projLoad);

If the third line should timeout, the program has no way to throw an error based on runtime or to check for threadInterrupted()

Answer Source

You must be looking at old javadocs. In the current release (2.4) here is an overload of the copyURLToFile method that has two timeout parameters:

  public static void copyURLToFile(URL source,
                             File destination,
                             int connectionTimeout,
                             int readTimeout)
                      throws IOException

Reference: https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/FileUtils.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download