How would I be able to handle downloads using HttpResponse in Java? I made an HttpGet request to a specific site - the site returns the file to be downloaded. How can I hand
Open a stream and send the file:
try {
FileInputStream is = new FileInputStream( _backupDirectory + filename );
OutputStream os = response.getOutputStream();
byte[] buffer = new byte[65536];
int numRead;
while ( ( numRead = is.read( buffer, 0, buffer.length ) ) != -1 ) {
os.write( buffer, 0, numRead );
}
os.close();
is.close();
}
catch (FileNotFoundException fnfe) {
System.out.println( "File " + filename + " not found" );
}