Java BufferedInputStream Copy copyFile(String from, String to)

Here you can find the source of copyFile(String from, String to)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String from, String to) throws IOException 

Method Source Code

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

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 from, String to) throws IOException {
        File inCannon = new File(from);
        File outCannon = new File(to);

        // [#20196] Installer overwrites the installed credentials if already installed credentials are selected
        // Applies to Windows only
        if (inCannon.equals(outCannon)) {
            return;
        }//from  w ww .  j  av a 2  s.  co m

        // ensure the output file location exists
        outCannon.getParentFile().mkdirs();

        BufferedInputStream fis = new BufferedInputStream(new FileInputStream(inCannon));
        BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(outCannon));

        // a temporary buffer to read into
        byte[] tmpBuffer = new byte[8192];
        int len = 0;
        while ((len = fis.read(tmpBuffer)) != -1) {
            // add the temp data to the output
            fos.write(tmpBuffer, 0, len);
        }
        // close the input stream
        fis.close();
        // close the output stream
        fos.flush();
        fos.close();
    }
}

Related

  1. copyFile(InputStream is, File newFile)
  2. copyFile(InputStream src, File dest)
  3. copyFile(InputStream src, File dst)
  4. copyFile(String dest_path, String src_path)
  5. copyFile(String fileName, File sourceRoot, File targetRoot, Set copied)
  6. copyFile(String fromFile, String toFile)
  7. copyFile(String source, String dest)
  8. copyFile(String source, String destination)
  9. copyFile(String source, String destination)