Java BufferedInputStream Copy copyFile(String source, String destination)

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

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String source, String destination) throws IOException 

Method Source Code


//package com.java2s;
/*//from  www .j a  v  a 2 s.c om
 * Copyright 2004 by EkoLiving Pty Ltd.  All Rights Reserved.
 *
 * This software is the proprietary information of EkoLiving Pty Ltd.
 * Use is subject to license terms.
 */

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    private static final int BUFFER_SIZE = 16384;

    public static void copyFile(String source, String destination) throws IOException {
        BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(source));
        BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(destination));
        int bytes;
        byte[] buffer = new byte[BUFFER_SIZE];

        while ((bytes = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, bytes);
        }
        outputStream.flush();
        outputStream.close();
        inputStream.close();
    }
}

Related

  1. copyFile(String dest_path, String src_path)
  2. copyFile(String fileName, File sourceRoot, File targetRoot, Set copied)
  3. copyFile(String from, String to)
  4. copyFile(String fromFile, String toFile)
  5. copyFile(String source, String dest)
  6. copyFile(String source, String destination)
  7. copyFile(String sourceFilePath, String destinationFilePath)
  8. copyFile(String src, String dest)
  9. copyFileBytes(String srcFileName, String tarFileName)