<pre>public static boolean processHttpRequestBytes(String url, String filename) throws IOException {
// the size of my buffer in bits
int bufferSize = 4096
byte[] retVal = null;
InputStream in = null;
OutputStream fileos = null;
long numBytesDownloaded = 0;
HttpURLConnection urlConnection;
try {
// opens a new url connection
urlConnection = (HttpURLConnection) new URL(urlString).openConnection();
// open the file output stream for file writing
fileos = new BufferedOutputStream(new FileOutputStream(filename));
// open the url input stream for reading the connection
in = new BufferedInputStream(urlConnection.getInputStream(), BUFFER_SIZE);
// write the file from the connection inputstream
retVal = new byte[BUFFER_SIZE];
int length = 0;
while((length = in.read(retVal)) > -1) {
fileos.write(retVal, 0, length);
numBytesDownloaded += length;
}
} catch(IOException e) {
Log.e(TAG, e.getMessage());
return false;
} finally {
Log.v(TAG, "Response Code: " + urlConnection.getResponseCode());
Log.v(TAG, "Bytes download: " + numBytesDownloaded);
if(fileos != null) {
fileos.flush();
fileos.close();
}
if(in != null) {
in.close();
}
urlConnection.disconnect();
}
return true;
}</pre>