Java FileInputStream Copy copyFile(File src, File target)

Here you can find the source of copyFile(File src, File target)

Description

copy File

License

Apache License

Declaration

public static boolean copyFile(File src, File target) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static boolean copyFile(File src, File target) {
        FileOutputStream fs = null;
        InputStream inStream = null;
        try {/*from   w ww . j av  a 2s.  co m*/
            int byteread = 0;
            fs = new FileOutputStream(new File(target.getAbsolutePath()));
            inStream = new FileInputStream(src);
            if (src.exists()) {
                byte[] buffer = new byte[4096];
                while ((byteread = inStream.read(buffer)) != -1) {
                    fs.write(buffer, 0, byteread);
                }
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (inStream != null) {
                    inStream.close();
                }
                if (fs != null) {
                    fs.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. copyFile(File src, File dst)
  2. copyFile(File src, File dst)
  3. copyFile(File src, File dst)
  4. copyFile(File src, File dst)
  5. copyFile(File src, File dst, boolean copyLMD)
  6. copyFile(File src, File toDir)
  7. copyFile(File srcFile, File destFile)
  8. copyFile(File srcFile, File destFile)
  9. copyFile(File srcFile, File destFile)