Java FileInputStream Copy copyFile(File fromFile, File toFile)

Here you can find the source of copyFile(File fromFile, File toFile)

Description

Legacy method to copy a file from one location to another

License

Open Source License

Parameter

Parameter Description
fromFile File to be copied
toFile Destination File

Exception

Parameter Description
FileNotFoundException if fromFile was not found
IOException if operation fails

Declaration

@Deprecated
public static void copyFile(File fromFile, File toFile) throws FileNotFoundException, IOException 

Method Source Code


//package com.java2s;
/*//from w w  w  .  jav  a 2 s.  c om
Copyright 2012 Juan Mart?n Runge
    
jmrunge@gmail.com
http://www.zirsi.com.ar
    
This file is part of ZirUtils.
    
ZirUtils 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.
    
ZirUtils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with ZirUtils.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.io.*;

public class Main {
    /**
     * Legacy method to copy a file from one location to another
     * 
     * @param fromFile File to be copied
     * @param toFile Destination File
     * @throws FileNotFoundException if fromFile was not found
     * @throws IOException if operation fails
     * @deprecated
     */
    @Deprecated
    public static void copyFile(File fromFile, File toFile) throws FileNotFoundException, IOException {
        FileOutputStream to;
        try (FileInputStream from = new FileInputStream(fromFile)) {
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) > 0)
                to.write(buffer, 0, bytesRead);
        }
        to.close();
    }
}

Related

  1. copyFile(File from, File to)
  2. copyFile(File from, File to)
  3. copyFile(File from, File to, byte[] buf)
  4. copyFile(File from, File toDir)
  5. copyFile(File from, File toFile)
  6. copyFile(File fromFile, File toFile)
  7. copyFile(File fromFile, File toFile)
  8. copyFile(File fromFile, File toFile, IProgressMonitor monitor)
  9. copyFile(File in, File out)