Here you can find the source of copyResource(URL resource, File destination)
public static void copyResource(URL resource, File destination) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; public class Main { public static void copyResource(URL resource, File destination) throws IOException { if (resource == null) { throw new IllegalArgumentException("URL must not be null."); }//from www . ja v a 2 s . c om if (destination == null) { throw new IllegalArgumentException("URL must not be null."); } try (InputStream inStream = resource.openStream()) { File parent = destination.getParentFile(); if ((parent != null) && (!parent.exists())) { if (!parent.mkdirs()) { throw new IOException("Could not create target directory '" + parent + "'."); } } try (FileOutputStream outStream = new FileOutputStream(destination)) { byte[] buffer = new byte[1024]; int amount; while ((amount = inStream.read(buffer)) >= 0) { outStream.write(buffer, 0, amount); } } } } }