Here you can find the source of fileCopy(String oldFilePath, String newFilePath, boolean isCover)
public static boolean fileCopy(String oldFilePath, String newFilePath, boolean isCover)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static boolean fileCopy(String oldFilePath, String newFilePath, boolean isCover) { if (!checkFile(oldFilePath, false)) { return false; }//from w ww . ja va 2 s . c o m if (checkFile(newFilePath, true) && (!isCover)) { return false; } FileInputStream in = null; FileOutputStream out = null; byte[] buff = new byte[4096]; try { in = new FileInputStream(oldFilePath); out = new FileOutputStream(newFilePath); int len = 0; while ((len = in.read(buff)) > 0) { out.write(buff, 0, len); } } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } finally { try { if (in != null) { in.close(); } } catch (IOException e) { } try { if (out != null) { out.close(); } } catch (IOException e) { } } return true; } public static boolean checkFile(String file, boolean create) { File f = new File(file); if (f.getParent() != null) { File fpath = new File(f.getParent()); if (!fpath.exists()) { if (create) { fpath.mkdirs(); } else { return false; } } } if (!f.exists()) { if (create) { try { f.createNewFile(); } catch (IOException e) { return false; } } else { return false; } } return true; } }