Java Reference
In-Depth Information
URL u = new URL(page);
String str = downloadPage(u);
System.out.println(str);
} catch (MalformedURLException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
/**
* Typical Java main method, create an object, and then
* call that object's go method.
*
* @param args Website to access.
*/
public static void main(String args[])
{
GetPage module = new GetPage();
String page;
if (args.length == 0)
page = "http://www.httprecipes.com/1/3/time.php";
else
page = args[0];
module.go(page);
}
}
The above example can be run in two ways. If you run the example without any param-
eters (by simply typing “java GetSite”), it will download from the following URL, which is
hardcoded in the recipe:
http://www.httprecipes.com/1/3/time.php
If you run the program with arguments it will download the specified URL. For example,
to download the contents of the homepage of the recipes site, you would use the following
command:
GetSite http://www.httprecipes.com
Search WWH ::




Custom Search