To read data from an URL with JAVA
2007-03-05 04:20:33
To read the data inside a file from the Web with Java is fairly easy. Just create an URL object (remember to import java.io.* to have it avaliable for your code) and tunnel its stream to the usual InputStreamReader.
Just be aware that it doesn't seem to support HTTP authentication!
import java.net.*;import java.io.*;
public class URLReader
{
public static void main(String[] args) throws Exception
{
URL pagina = new URL("http://www.google.com/");
BufferedReader in = new BufferedReader
(new InputStreamReader(pagina.openStream()));
String entrada;
while ((entrada = in.readLine()) != null)
System.out.println(entrada);
in.close();
}
}