copy the content of a file to another file.

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();
    }
 } 

猜你喜欢

转载自blog.csdn.net/java_augur/article/details/510184