Here you can find the source of copyFile(String resourceFimeName, String targetFileName)
public static boolean copyFile(String resourceFimeName, String targetFileName) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static boolean copyFile(String resourceFimeName, String targetFileName) throws IOException { return copyFile(new File(resourceFimeName), new File(targetFileName)); }/* w w w .j av a 2 s .com*/ public static boolean copyFile(String resourceFimeName, File targetFile) throws IOException { return copyFile(new File(resourceFimeName), targetFile); } public static boolean copyFile(File resourceFile, String targetFileName) throws IOException { return copyFile(resourceFile, new File(targetFileName)); } public static boolean copyFile(File resourceFile, File targetFile) throws IOException { if (resourceFile == null || targetFile == null) return false; if (resourceFile.exists()) { if (!targetFile.exists()) { File parentFile = targetFile.getParentFile(); if (!parentFile.exists()) parentFile.mkdirs(); targetFile.createNewFile(); } FileInputStream in = new FileInputStream(resourceFile); FileOutputStream out = new FileOutputStream(targetFile); byte[] buffer = new byte[1024 * 8]; int i = 0; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } out.flush(); in.close(); out.close(); return true; } else { return false; } } }