URLDumperpublic class URLDumper extends Object A simple example to illustrate using a URL to access a resource
and then store the result to a File.
Any type of URL can be used: http, https, ftp, etc. |
Methods Summary |
---|
public static void | main(java.lang.String[] args)
if (args.length != 2) {
System.out.println("Usage: URLDumper <URL> <file>");
System.exit(1);
}
String location = args[0];
String file = args[1];
URL url = new URL(location);
FileOutputStream fos = new FileOutputStream(file);
byte [] bytes = new byte [4096];
InputStream is = url.openStream();
int read;
while ((read = is.read(bytes)) != -1) {
fos.write(bytes, 0, read);
}
is.close();
fos.close();
|
|