Java Reference
In-Depth Information
/**
* Download a binary file from the Internet.
*
* @param page The web URL to download.
* @param filename The local file to save to.
*/
public void download(String page, String filename)
{
try
{
URL u = new URL(page);
String str = downloadPage(u);
saveBinaryPage(filename, str);
} catch (MalformedURLException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
/**
* Typical Java main method, create an object, and then
* start that object.
*
* @param args URL to download, and local file.
*/
public static void main(String args[])
{
try
{
if (args.length != 2)
{
DownloadBinary d = new DownloadBinary();
d.download("http://www.httprecipes.com/1/3/sea.jpg",
"./sea2.jpg");
} else
{
DownloadBinary d = new DownloadBinary();
d.download(args[0], args[1]);
}
} catch (Exception e)
{
e.printStackTrace();
Search WWH ::




Custom Search