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 final void copyFile(File in, File out) 

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;

public class Main {
    public static final void copyFile(File in, File out) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {//w  ww  .j a  va 2 s . c  o m
            fis = new FileInputStream(in);
            fos = new FileOutputStream(out);
            byte[] buf = new byte[1024];
            int i = 0;
            while ((i = fis.read(buf)) != -1) {
                fos.write(buf, 0, i);
            }
        } catch (IOException ie) {
            throw new RuntimeException(ie);
        } finally {
            if (null != fis) {
                try {
                    fis.close();
                } catch (IOException e) {
                    fis = null;
                    throw new RuntimeException(e);
                }
            }
            if (null != fos) {
                try {
                    fos.close();
                } catch (IOException e) {
                    fos = null;
                    throw new RuntimeException(e);
                }
            }
        }
    }

    public static final void copyFile(String infile, String outfile) {
        File in = new File(infile);
        File out = new File(outfile);
        copyFile(in, out);
    }
}

Related

  1. copyFile(File fromFile, File toFile)
  2. copyFile(File fromFile, File toFile)
  3. copyFile(File fromFile, File toFile, IProgressMonitor monitor)
  4. copyFile(File in, File out)
  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)