Java File Copy fileCopy(String sourceFile, String destinationFile)

Here you can find the source of fileCopy(String sourceFile, String destinationFile)

Description

file Copy

License

Open Source License

Declaration

public static boolean fileCopy(String sourceFile, String destinationFile) 

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 boolean fileCopy(String sourceFile, String destinationFile) {
        boolean resultado = true;
        try {//from   w w w.ja  v  a  2 s. co m
            File inFile = new File(sourceFile);
            File outFile = new File(destinationFile);
            FileInputStream in = new FileInputStream(inFile);
            FileOutputStream out = new FileOutputStream(outFile);
            BufferedInputStream bis = new BufferedInputStream(in);
            BufferedOutputStream bos = new BufferedOutputStream(out);
            byte[] buffer = new byte[32 * 1024];
            int leido = 0;
            while ((leido = bis.read(buffer)) != -1) {
                bos.write(buffer, 0, leido);
            }

            bis.close();
            bos.close();
            in.close();
            out.close();
        } catch (IOException e) {
            System.err.println("Hubo un error de entrada/salida!!! " + e);
            resultado = false;
        }
        return resultado;
    }
}

Related

  1. fileCopy(String from, String to)
  2. fileCopy(String fromPath, String toPath)
  3. fileCopy(String oldFilePath, String newFilePath, boolean isCover)
  4. fileCopy(String sFrom, String sTo)
  5. fileCopy(String source, String target)
  6. fileCopy(String sourcefile, String destinctionFile)
  7. workaroundCopyFile(final File src, final File dest)