Here you can find the source of saveURL(URL url, OutputStream os)
public static void saveURL(URL url, OutputStream os) throws IOException
//package com.java2s; import java.net.*; import java.io.*; public class Main { /**// www . j a v a2s .co m * Opens a buffered stream on the url and copies the contents to writer */ public static void saveURL(URL url, Writer writer) throws IOException { BufferedInputStream in = new BufferedInputStream(url.openStream()); for (int c = in.read(); c != -1; c = in.read()) { writer.write(c); } } /** * Opens a buffered stream on the url and copies the contents to OutputStream */ public static void saveURL(URL url, OutputStream os) throws IOException { InputStream is = url.openStream(); byte[] buf = new byte[1048576]; int n = is.read(buf); while (n != -1) { os.write(buf, 0, n); n = is.read(buf); } } }