In Java, you can use URLConnection class to read from an URL. For example, to read the page from google.com, you can do something like this:
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL google = new URL("http://www.google.com/");
URLConnection gc = google.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
gc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
If the access to the URL is protected with authentication mechanism, IOException is thrown when you try to read from InputStream associated with URLConnection. In that case, you need to use Authenticator class from java.net package, that makes accessing password-protected URLs as easy as can be.