Java FileInputStream Copy copyFile(File inFile, File outFile)

Here you can find the source of copyFile(File inFile, File outFile)

Description

copy File

License

Open Source License

Declaration

private static File copyFile(File inFile, File outFile) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    private static File copyFile(File inFile, File outFile) {
        try {//from   w  ww. j  ava2s  . c om
            assert inFile.isFile();
            assert outFile.getParentFile().isDirectory();

            InputStream is = new FileInputStream(inFile);
            copyStreamIntoFile(outFile, is);

            return outFile;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static void copyStreamIntoFile(File outFile, InputStream is) throws IOException {
        OutputStream os = new FileOutputStream(outFile);

        byte[] buf = new byte[1024];
        int len;
        while ((len = is.read(buf)) > 0) {
            os.write(buf, 0, len);
        }

        is.close();
        os.close();
    }
}

Related

  1. copyFile(File in, File out)
  2. copyFile(File in, File out)
  3. copyFile(File in, File out)
  4. copyFile(File in, File out)
  5. copyFile(File inFile, File outFile)
  6. copyFile(File input, File output)
  7. copyFile(File inputFile, File outputFile)
  8. copyFile(File inputFile, File outputFile)
  9. copyFile(File inputFile, File outputFile)