Here you can find the source of copyFromURL(final String query, final File target)
public static void copyFromURL(final String query, final File target) 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 { /** copy data from URL to the target file **/ public static void copyFromURL(final String query, final File target) throws IOException { final URL url = new URL(query); final InputStream in = url.openStream(); final OutputStream fous = new FileOutputStream(target); final byte buff[] = new byte[0x3FF]; int sz = 0; try {/*from w w w . jav a 2 s . c o m*/ while ((sz = in.read(buff)) >= 0) { fous.write(buff, 0, sz); } } finally { fous.close(); } } }