Java FileInputStream Copy copyFile(String srFile, String dtFile)

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

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String srFile, String dtFile) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static void copyFile(String srFile, String dtFile) {
        try {/*from   w ww  .j  a v a 2s  .  c o  m*/
            File f1 = new File(srFile);
            File f2 = new File(dtFile);
            InputStream in = new FileInputStream(f1);
            OutputStream out = new FileOutputStream(f2);

            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) {
            System.err.println(ex.getMessage() + " in the specified directory.");
            System.exit(0);
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

Related

  1. copyFile(String srcFileName, String destFileName)
  2. copyFile(String srcFilename, String dtsFilename)
  3. copyFile(String srcFilePath, String destFilePath)
  4. copyFile(String srcPath, String dstPath)
  5. copyFile(String srcPath, String dstPath, boolean replace)
  6. copyFile(String srFile, String dtFile)
  7. copyFile(String srFile, String dtFile)
  8. copyFile(String srFilePath, String dtFilePath)
  9. copyFile(String target, String source)