Java FileInputStream Copy copyFile(String src, String to)

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

Description

copy File

License

Open Source License

Declaration

public static int copyFile(String src, String to) 

Method Source Code


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

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

public class Main {
    public static int copyFile(String src, String to) {
        return copyFile(new File(src), new File(to));
    }/*  www  .j  ava2 s  .c o m*/

    public static int copyFile(File in, File out) {

        try {
            FileInputStream fis = new FileInputStream(in);
            FileOutputStream fos = new FileOutputStream(out);

            byte[] buf = new byte[1024];
            int i = 0;
            while ((i = fis.read(buf)) != -1) {
                fos.write(buf, 0, i);
            }
            fis.close();
            fos.close();
            fis = null;
            fos = null;
        } catch (Exception e) {
            System.err.println(e);
            return -1;
        }
        return 1;
    }
}

Related

  1. copyFile(String src, String dest)
  2. copyFile(String src, String dest)
  3. copyFile(String src, String dst)
  4. copyFile(String src, String dst)
  5. copyFile(String src, String tar)
  6. copyFile(String srcDir, String destDir)
  7. copyFile(String srcFile, String destFile)
  8. copyFile(String srcFile, String dstFile)
  9. copyFile(String srcFile, String dstFile)