Java FileInputStream Copy copyFile(String srFilePath, String dtFilePath)

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

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String srFilePath, String dtFilePath) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

public class Main {

    public static void copyFile(String srFilePath, String dtFilePath) {
        try {/* w ww  .ja v a 2  s  . c  o m*/
            File srFile = new File(srFilePath);
            File dtFile = new File(dtFilePath);

            InputStream in = new FileInputStream(srFile);
            OutputStream out = new FileOutputStream(dtFile);

            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. copyFile(String srcPath, String dstPath)
  2. copyFile(String srcPath, String dstPath, boolean replace)
  3. copyFile(String srFile, String dtFile)
  4. copyFile(String srFile, String dtFile)
  5. copyFile(String srFile, String dtFile)
  6. copyFile(String target, String source)
  7. copyFileAndReName(String destPath, String srcPath, String srcFile, String destFile)
  8. copyFileAsStream(String srcFilePathName, String dstFilePathName)
  9. copyFileBin(File sourceFile, File targetFile)