Note that there are some explanatory texts on larger screens.

plurals
  1. POMethods for downloading files from a URL in Java
    text
    copied!<p>I want to download a binary file from a webserver which is running on a embedded device. That file can be downloaded manually after a basic http authentication by using that URL: <code>http://10.10.10.10/config.bin</code>... Now i want to automate this process with a simple Java application. By using the basic java tools i managed to download the file:</p> <pre><code>URL mlrrl = new URL(url); HttpURLConnection con = (HttpURLConnection) mlrUrl.openConnection(); con.setRequestMethod("GET"); con.setAllowUserInteraction(false); con.setDoInput(true); con.setDoOutput(true); con.setConnectTimeout(10000); con.setRequestProperty("Authorization", "Basic " + authStringEnc); InputStream stream = con.getInputStream(); BufferedInputStream in = new BufferedInputStream(stream); FileOutputStream file = new FileOutputStream("configDown.bin"); BufferedOutputStream out = new BufferedOutputStream(file); int i; while ((i = in.read()) != -1) { out.write(i); } out.flush(); </code></pre> <p>That seemed to work fine! In comparison with the manually (by Browser-Webinterface) downloaded file the generated file have the same length, but after opening both binaries with a hex-editor they were different. </p> <p>My questions: </p> <ol> <li>Any ideas why the hex-codes are different? (Maybe missing connection properties?)</li> <li>There is a copyUrlToFile-Method in the apache.commons package. Is it possible to use it with basic http authentification, as a alternative?</li> <li>Are there other java libs or tools for downloading files from urls?</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload