FileDocCategorySizeDatePackage
URLDumper.javaAPI DocSun JDK 1.5.0 Example2661Sat Jan 08 15:08:43 GMT 2005None

URLDumper

public 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.

author
Brad R. Wetmore
author
Mark Reinhold
version
1.2, 04/07/26

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(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();