Java FileInputStream Copy copyFileFromFileToFile(File fromFile, File toFile)

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

Description

copy File From File To File

License

Apache License

Declaration

public static void copyFileFromFileToFile(File fromFile, File toFile) throws IOException 

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;
import java.io.OutputStream;

public class Main {
    public static void copyFileFromFileToFile(File fromFile, File toFile) throws IOException {
        FileInputStream in = new FileInputStream(fromFile);
        FileOutputStream out = new FileOutputStream(toFile);
        copyFile(in, out);//ww  w. ja v  a 2s .  c  om

        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
    }

    public static void copyFile(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
    }
}

Related

  1. copyFileAsStream(String srcFilePathName, String dstFilePathName)
  2. copyFileBin(File sourceFile, File targetFile)
  3. copyFileBinary(String source, String destination)
  4. copyFileContents(File fromFile, File destination, boolean useTempFilenames)
  5. copyFileFolder(final File source, final File dest, final boolean override)
  6. copyFileFromTo(String filename, File fromDir, File toDir)
  7. copyFileLowLevel(File source, File target)
  8. copyFileR(File srcFile, File destDirectory)
  9. copyFileRecursive(File src, File dest)