Skip to content

Instantly share code, notes, and snippets.

@novln
Created April 2, 2013 17:52
Show Gist options
  • Save novln/5294496 to your computer and use it in GitHub Desktop.
Save novln/5294496 to your computer and use it in GitHub Desktop.
public void download(String url) {
BufferedReader reader = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response = client.execute(get);
StatusLine status = response.getStatusLine();
if(status.getStatusCode() != 200) {
throw new IOException("Cannot download list of URL");
}
HttpEntity entity = response.getEntity();
reader = new BufferedReader(new InputStreamReader(entity.getContent()));
String line;
while ((line = reader.readLine()) != null) {
// DO SOMETHING
}
} catch(Exception e) {
Log.e("URL Download", "An error has occurred...", e);
} finally {
if(reader != null) {
try { reader.close(); } catch (Exception e) {}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment