Java FileInputStream Copy copyFile(File in, File out)

Here you can find the source of copyFile(File in, File out)

Description

copy File

License

Open Source License

Declaration

public static boolean copyFile(File in, File out) throws Exception 

Method Source Code


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

import java.io.*;

public class Main {
    public static boolean copyFile(File in, File out) throws Exception {
        try {//  w  ww . j a va  2 s .  c  om
            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();
            return true;
        } catch (IOException ie) {
            ie.printStackTrace();
            return false;
        }
    }

    public static boolean copyFile(String infile, String outfile) throws Exception {
        try {
            File in = new File(infile);
            File out = new File(outfile);
            return copyFile(in, out);
        } catch (IOException ie) {
            ie.printStackTrace();
            return false;
        }

    }
}

Related

  1. copyFile(File fromFile, File toFile)
  2. copyFile(File fromFile, File toFile)
  3. copyFile(File fromFile, File toFile)
  4. copyFile(File fromFile, File toFile, IProgressMonitor monitor)
  5. copyFile(File in, File out)
  6. copyFile(File in, File out)
  7. copyFile(File in, File out)
  8. copyFile(File in, File out)
  9. copyFile(File in, File out)