Thursday, April 26, 2007

Read data from a URL and show them on screen with Java

The following code reads data from a URL and then it shows them on screen. This is an amateur example of the use of java.net packet. If you are an experienced user, you can use ContentHandler and ContentHandlerFactory to choose who can be a data controller.
import java.io.*;
import java.net.*;
public class ReadUrl
{
public static void main (String[] args)
{
for (int i = 0; i < url =" new" connect =" url.openConnection();" in =" connect.getInputStream();" bytes =" new" len =" in.read(bytes))">= 0)
System.out.write(bytes, 0, len);
}
}

No comments: