Java FileInputStream Copy copyFile(String inFile, String outFile)

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

Description

Copia um arquivo.

License

Open Source License

Parameter

Parameter Description
inFile a parameter
outFile a parameter

Declaration

public static boolean copyFile(String inFile, String outFile) 

Method Source Code

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

import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

public class Main {
    /**//from  w w w  . j a v  a  2  s . co m
     * Copia um arquivo.
     * @param inFile
     * @param outFile
     * @return
     */
    public static boolean copyFile(String inFile, String outFile) {
        InputStream is = null;
        OutputStream os = null;
        byte[] buffer;
        boolean success = true;
        try {
            is = new FileInputStream(inFile);
            os = new FileOutputStream(outFile);
            buffer = new byte[is.available()];
            is.read(buffer);
            os.write(buffer);

        } catch (IOException e) {
            success = false;
        } catch (OutOfMemoryError e) {
            success = false;
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            }
            try {
                if (os != null) {
                    os.close();
                }
            } catch (IOException e) {
            }
        }
        is = null;
        os = null;
        return success;
    }
}

Related

  1. copyFile(String fileName, String fromDir, String toDir)
  2. copyFile(String fileOutPut, String fileIn)
  3. copyFile(String from, String to)
  4. copyFile(String fromFile, String toFile)
  5. copyFile(String fromFilePath, String toFilePath)
  6. copyFile(String inFileName, String outFileName)
  7. copyFile(String input, String output)
  8. copyFile(String inputFile, String outputFile)
  9. copyFile(String oldFile, String newFile)