Java FileInputStream Copy copyfile(File srFile, File dtFile)

Here you can find the source of copyfile(File srFile, File dtFile)

Description

copyfile

License

Open Source License

Declaration

public static void copyfile(File srFile, File dtFile) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static void copyfile(File srFile, File dtFile) throws IOException {
        InputStream in = new FileInputStream(srFile);

        File desDir = dtFile.getParentFile();
        if (!desDir.exists()) {
            boolean ret = desDir.mkdirs();
            if (!ret)
                throw new IOException("Cannot create directory " + desDir.getName());
        }/*from   ww w . ja  va  2  s . c o m*/

        // For Overwrite the file.
        OutputStream out = new FileOutputStream(dtFile);

        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();

    }
}

Related

  1. copyFile(File srcFile, File dstFile)
  2. copyFile(File srcFile, File dstFile)
  3. copyFile(File srcFile, File dstFile)
  4. copyFile(File srcFile, File dstFile)
  5. copyFile(File srcPath, File dstPath)
  6. copyFile(File target, File source)
  7. copyFile(File targetFile, File file)
  8. copyFile(File targetFile, File file)
  9. copyFile(final File from, final File to)