Created
April 2, 2013 17:52
-
-
Save novln/5294496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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