Read URL content in JAVA

Posted By: Matpal - March 10, 2011
This program shows how to read content of any URL in JAVA. For demonstration we have taken the example of http://google.com

import java.net.*;
import java.io.*;

public class URLReader
{
 public static void main(String[] args) throws Exception {
 URL google = new URL("http://www.google.com/");
 BufferedReader in = new BufferedReader( new   InputStreamReader(google.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();

 }

}

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.