Reading data from Internet

This URL seems to be pretty useful for this purpose.

Always use BufferedReader while reading InputStreams. Not using BufferedReader would lead to corrupt data and may not give correct results.

Code snippet is as given below :

HttpURLConnection hpCon;
hp = new URL(url);
hpCon = (HttpURLConnection)hp.openConnection();
InputStream in = hpCon.getInputStream();
InputStreamReader inStream = new InputStreamReader(in);
BufferedReader input = new BufferedReader(inStream);

String tempString="";

tempString = input.readLine();
if(tempString == null) break;
hp = null;
hpCon = null;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.