Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Download multiple files with 1 HttpURLConnection

843790Aug 28 2006 — edited Aug 30 2006
Hi,

We have an application that downloads small text files (< 2 Kb) from a webserver. These files are downloaded 1 by 1 when needed. We open a HttpURLConnection, download 1 file and close the connection immediately afterwards. This is done for each file and hence produces a significant overhead.
For performance reasons (both client and server side), we would like to open a connection to the webserver once, download a number of files and then close the connection.
Currently, our code roughly looks like:
InputStream is;
HttpURLConnection con;
int resp;
try {
    URL url = new URL(location);
    con = (HttpURLConnection)url.openConnection();
    resp=con.getResponseCode();
    if(resp==HttpURLConnection.HTTP_OK) {
        is = con.getInputStream();
        // ... read data from the InputStream
        is.close();
    }
} catch (MalformedURLException murle) {
    murle.printStackTrace();
} catch (IOException ioe) {
    ioe.printStackTrace();
}
Is it even possible to download multiple files from a web server using a HttpURLConnection? If so, how? :-)
Please note that the solution should be compliant with J2SE 1.1, since we are writing an MHP application!

Thanks in advance...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2006
Added on Aug 28 2006
3 comments
447 views