/* Java Program To Fetch The Url Of Any Site */
import java.io.*;
import java.net.*;
public class fetchUrl
{
public static void main(String args[])
{
try
{
if(args.length !=1)
{
System.out.println("Usage: java fetchUrl < URL such as http://www.javapgms.blogspot.com>");
System.exit(0);
}
System.out.println("Hello");
URL url = new URL (args[0]);
System.out.println("\n Fetching URL :" +args[0] +"\n");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String strline;
while((strline = br.readLine())!=null)
{
System.out.println(strline);
}
br.close();
}
catch(MalformedURLException mue)
{
System.out.println("Unknown URL");
}
catch(IOException ioe)
{
System.out.println("IO Error");
}
}
}
Labels: Advanced Java, Networking, Thread
Subscribe to:
Post Comments (Atom)
Post a Comment