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

public static void copyFile(String sourceFilePath, String destinationFilePath) 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(String sourceFilePath, String destinationFilePath) throws IOException {
        InputStream in = null;//w w w  .ja  va 2  s. c  o  m
        OutputStream out = null;
        try {
            in = new FileInputStream(new File(sourceFilePath));
            out = new FileOutputStream(new File(destinationFilePath));

            // Transfer bytes from in to out
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
            }
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException ex) {
            }
        }
    }
}

Related

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