Java FileReader Copy copyFile(String srcFileName, String dstFileName)

Here you can find the source of copyFile(String srcFileName, String dstFileName)

Description

Copy a file.

License

Open Source License

Declaration

public static synchronized void copyFile(String srcFileName, String dstFileName) throws IOException 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * The contents of this file are subject to the Ricoh Source Code Public
 * License Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License.  You may obtain a copy of the License at
 * http://www.risource.org/RPL/*from w ww .  j  a  v a2s. com*/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * This code was initially developed by Ricoh Innovations, Inc.  Portions
 * created by Ricoh Innovations, Inc. are Copyright (C) 1995-1999.  All
 * Rights Reserved.
 *
 * Contributor(s):
 *
 ***************************************************************************** 
*/

import java.io.*;

public class Main {
    /**
     * Copy a file.
     */
    public static synchronized void copyFile(String srcFileName, String dstFileName) throws IOException {
        copyFile(new File(srcFileName), new File(dstFileName));
    }

    public static synchronized void copyFile(File src, File dst) throws IOException {

        System.err.println("Substituting " + src.getPath() + "->" + dst.getPath());

        FileWriter destination = null;
        FileReader source = null;

        try {
            source = new FileReader(src);
            destination = new FileWriter(dst);
            for (int i = source.read(); i != -1; i = source.read()) {
                destination.write((char) i);
            }
            destination.flush();
        } catch (IOException e1) {
            // either from open or write.
            throw e1;
        } finally {
            if (source != null)
                source.close();
            if (destination != null)
                destination.close();
        }
    }
}

Related

  1. copyFile(File source, File destination)
  2. copyFile(String fromFilePath, String toFileDir)
  3. copyFile(String input, String output)
  4. copyFile(String inputName, String destination)
  5. copyFile(String sourceFileName, String targetFileName)
  6. copyFileToDir(File inputFile, File outputDir)