Java: Download File

The following code will allow you to download a file in java from a source URL to a target File.

public static void download(URL orig, File dest) throws IOException {
	OutputStream os = null;
	InputStream is = null;
	try {
		byte[] buf;
		int count, length = 0;
		os = new BufferedOutputStream(new FileOutputStream(dest));
		is = orig.openConnection().getInputStream();
		buf = new byte[4096];
		while ((count = is.read(buf)) != -1) {
			os.write(buf, 0, count);
			length += count;
		}
	} finally {
		is.close();
		os.close();
	}
}

Read More