Here you can find the source of writeFile(File src, File dst)
public static void writeFile(File src, File dst) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static void writeFile(File src, File dst) throws IOException { File parent = dst.getParentFile(); if (!parent.exists()) parent.mkdirs();//from www . j a va2 s . c o m byte[] bytes = loadBytes(new FileInputStream(src)); writeBytes(dst, bytes); if (!dst.exists()) throw new RuntimeException("UNABLE TO WRITE FILE: " + dst.getAbsolutePath()); } public static void writeFile(File file, String contents) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(contents); writer.flush(); writer.close(); writer = null; } public static byte[] loadBytes(InputStream input) throws IOException { BufferedInputStream bis = new BufferedInputStream(input); ByteArrayOutputStream out = new ByteArrayOutputStream(); int c = bis.read(); while (c != -1) { out.write(c); c = bis.read(); } return out.toByteArray(); } public static void writeBytes(File file, byte[] bytes) throws IOException { BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file)); bos.write(bytes); bos.flush(); bos.close(); } }