copy the content of a file to another file.

来源:互联网 发布:依云订水软件 编辑:程序博客网 时间:2024/04/30 13:18

public void copy(File src, File dst) throws IOException {
//if the parameters are same,then don't excute anything.or it make original file null.       

 if(!src.getAbsolutePath().equalsIgnoreCase(dst.getAbsolutePath())){
  InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst);
   
        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    }
 }