Java FileInputStream Copy copyFile(File original, File parent)

Here you can find the source of copyFile(File original, File parent)

Description

copy File

License

LGPL

Declaration

public static boolean copyFile(File original, File parent) 

Method Source Code


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

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

public class Main {
    public static boolean copyFile(File original, File parent) {
        try {/*  w w w.j  a  v a  2  s. co  m*/
            FileInputStream input = new FileInputStream(original);
            File outputFile = new File(parent, original.getName());
            FileOutputStream output = new FileOutputStream(outputFile);
            int data;
            while ((data = input.read()) != -1) {
                output.write(data);
            }
            input.close();
            output.close();
            return true;
        } catch (FileNotFoundException fnfe) {
            return false;
        } catch (IOException ioe) {
            return false;
        }
    }
}

Related

  1. copyFile(File oldFile, String newPath)
  2. copyFile(File orig, File dest)
  3. copyFile(File orig, File dest, boolean overwrite)
  4. copyFile(File original, File copy)
  5. copyFile(File original, File destination)
  6. copyFile(File originalFile, File destinationDir)
  7. copyFile(File pSrc, File pDst, boolean pForce)
  8. copyFile(File source, File dest)
  9. copyFile(File source, File dest)