Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I read data from the net (http)

IO / NET

How can I read data from the net (http)

by  FredrikN  Posted    (Edited  )
So you want to read data from the net.

This is one easy way you can do it
It creates a socket and then read line by line until the end of the file.

import java.io.*;
import java.net.*;
public class Driver
{
public static void main(String[] args) throws IOException
{
URL site = new URL("http://www.thegate.nu/uptime.php");
URLConnection con = site.openConnection();
BufferedReader data = new BufferedReader(new InputStreamReader(con.getInputStream()));

String d = data.readLine();

while(d != null)
{
System.out.println(d);
d = data.readLine();
}

data.close();
}
}
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top