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 downloadBinaryPage(URL url, File file) throws
IOException
{
byte buffer[] = new byte[BUFFER_SIZE];
OutputStream os = new FileOutputStream(file);
InputStream is = url.openStream();
int size = 0;
do
{
size = is.read(buffer);
if (size != -1)
os.write(buffer, 0, size);
} while (size != -1);
os.close();
is.close();
}
/**
* Extract just the filename from a URL.
* @param u The URL to extract from.
* @return The filename.
*/
private String extractFile(URL u)
{
String str = u.getFile();
// strip off path information
int i = str.lastIndexOf('/');
if (i != -1)
str = str.substring(i + 1);
return str;
}
/**
* Process the specified URL and download the images.
* @param url The URL to process.
* @param saveTo A directory to save the images to.
Search WWH ::




Custom Search