Java FileInputStream Copy copyFile(String input, String output)

Here you can find the source of copyFile(String input, String output)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String input, String output) 

Method Source Code


//package com.java2s;
/*/*  www.  j ava 2 s  . com*/
* Copyright 2002 - 2013 Pentaho Corporation.  All rights reserved.
* 
* This software was developed by Pentaho Corporation and is provided under the terms
* of the Mozilla Public License, Version 1.1, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://www.mozilla.org/MPL/MPL-1.1.txt. TThe Initial Developer is Pentaho Corporation.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to
* the license for the specific language governing your rights and limitations.
*/

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Main {
    public static void copyFile(String input, String output) {
        try {
            File inputFile = new File(input);
            File outputFile = new File(output);
            if (inputFile.exists() && !inputFile.getCanonicalPath().equals(outputFile.getCanonicalPath())) {
                FileInputStream fis = new FileInputStream(inputFile);
                FileOutputStream fos = new FileOutputStream(outputFile);
                fos.getChannel().transferFrom(fis.getChannel(), 0, fis.getChannel().size());
                fos.close();
                fis.close();
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
}

Related

  1. copyFile(String from, String to)
  2. copyFile(String fromFile, String toFile)
  3. copyFile(String fromFilePath, String toFilePath)
  4. copyFile(String inFile, String outFile)
  5. copyFile(String inFileName, String outFileName)
  6. copyFile(String inputFile, String outputFile)
  7. copyFile(String oldFile, String newFile)
  8. copyFile(String oldPath, String newPath)
  9. copyFile(String oldPath, String newPath)