Here you can find the source of copyFile(String dest_path, String src_path)
public static void copyFile(String dest_path, String src_path) throws IOException
//package com.java2s; /*/*from w w w. ja v a2 s. co m*/ * Copyright (C) 2005 Jeff Tassin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void copyFile(String dest_path, String src_path) throws IOException { if (dest_path == null) return; try { File f1 = new File(dest_path); File f2 = new File(src_path); if (f1.getCanonicalPath().equals(f2.getCanonicalPath())) { System.err.println("FormsDesignerUtils.copyFile dest and src are same."); return; } } catch (Exception e) { e.printStackTrace(); } FileInputStream fis = new FileInputStream(src_path); FileOutputStream fos = new FileOutputStream(dest_path); BufferedInputStream bis = new BufferedInputStream(fis); BufferedOutputStream bos = new BufferedOutputStream(fos); byte[] buff = new byte[1024]; int numread = bis.read(buff); while (numread > 0) { bos.write(buff, 0, numread); numread = bis.read(buff); } bos.flush(); bos.close(); bis.close(); } }