Java FileInputStream Copy copyFile(File original, File copy)

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

Description

Copies a file.

License

Open Source License

Declaration

public static boolean copyFile(File original, File copy) 

Method Source Code


//package com.java2s;
/*//from   w  w  w .ja  va 2 s.c o m
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 */

import java.io.*;

public class Main {
    /**
     *   Copies a file. Returns <code>true</code> on success.
     */
    public static boolean copyFile(File original, File copy) {
        try {
            FileInputStream fis = new FileInputStream(original);
            FileOutputStream fos = new FileOutputStream(copy);

            int len = fis.available();
            byte[] data = new byte[len];
            fis.read(data);
            fos.write(data);

            fis.close();
            fos.flush();
            fos.close();
        } catch (IOException ioe) {
            return false;
        }

        return true;
    }
}

Related

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