Here you can find the source of copy(URL fromUrl, File toFile)
public static void copy(URL fromUrl, File toFile) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; public class Main { public static void copy(URL fromUrl, File toFile) throws IOException { InputStream in = null;//w ww . j ava2 s. com OutputStream out = null; try { in = fromUrl.openStream(); out = new FileOutputStream(toFile); byte[] bytes = new byte[16384]; while (true) { int bytesRead = in.read(bytes); if (bytesRead < 0) break; out.write(bytes, 0, bytesRead); } } finally { if (in != null) try { in.close(); } catch (IOException e) { } if (out != null) try { out.close(); } catch (IOException e) { } } } }