Java FileInputStream Copy copyFile(String sourceFilePath, String destinationFilePath)

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

Description

copy File

License

Open Source License

Declaration

private static void copyFile(String sourceFilePath, String destinationFilePath) throws IOException 

Method Source Code

//package com.java2s;

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 {
    private static void copyFile(String sourceFilePath, String destinationFilePath) throws IOException {
        InputStream inStream = null;
        OutputStream outStream = null;
        File sourceFile = new File(sourceFilePath);
        File destinationFile = new File(destinationFilePath);

        inStream = new FileInputStream(sourceFile);
        outStream = new FileOutputStream(destinationFile); // for override file content
        // outStream = new FileOutputStream(file2,<strong>true</strong>); // for append file content

        byte[] buffer = new byte[1024];
        int length;
        while ((length = inStream.read(buffer)) > 0) {
            outStream.write(buffer, 0, length);
        }/*from w w w.  j  av  a  2  s.c  om*/

        if (inStream != null) {
            inStream.close();
        }
        if (outStream != null) {
            outStream.close();
        }
    }
}

Related

  1. copyFile(String sourceFile, String targetFile)
  2. copyFile(String sourceFile, String targetFolder)
  3. copyFile(String sourceFile, String targetFolder)
  4. CopyFile(String sourceFilePath, String destinationFilePath)
  5. copyFile(String sourceFilePath, String destinationFilePath)
  6. copyFile(String sourcePath, String newPath)
  7. copyFile(String src, File dest)
  8. copyFile(String src, String dest)
  9. copyFile(String src, String dest)