Java BufferedReader Copy copyFile2(String source, String out)

Here you can find the source of copyFile2(String source, String out)

Description

copy File

License

Open Source License

Parameter

Parameter Description
source a parameter
out a parameter

Declaration

public static boolean copyFile2(String source, String out) 

Method Source Code


//package com.java2s;
/*//from  w w w .j  av  a 2 s  .c o m
 * Copyright (c) 2004-2013 Universidade do Porto - Faculdade de Engenharia
 * Laborat?rio de Sistemas e Tecnologia Subaqu?tica (LSTS)
 * All rights reserved.
 * Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal
 *
 * This file is part of Neptus, Command and Control Framework.
 *
 * Commercial Licence Usage
 * Licencees holding valid commercial Neptus licences may use this file
 * in accordance with the commercial licence agreement provided with the
 * Software or, alternatively, in accordance with the terms contained in a
 * written agreement between you and Universidade do Porto. For licensing
 * terms, conditions, and further information contact lsts@fe.up.pt.
 *
 * European Union Public Licence - EUPL v.1.1 Usage
 * Alternatively, this file may be used under the terms of the EUPL,
 * Version 1.1 only (the "Licence"), appearing in the file LICENCE.md
 * included in the packaging of this file. You may not use this work
 * except in compliance with the Licence. Unless required by applicable
 * law or agreed to in writing, software distributed under the Licence is
 * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the Licence for the specific
 * language governing permissions and limitations at
 * https://www.lsts.pt/neptus/licence.
 *
 * For more information please see <http://lsts.fe.up.pt/neptus>.
 *
 * Author: Paulo Dias
 * 2005/01/14
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    /**
     * @deprecated - doesn't work for binary files!
     * @see FileUtil.copyFile(String source, String dest)
     * @param source
     * @param out
     * @return
     */
    public static boolean copyFile2(String source, String out) {
        try {
            FileReader fr = new FileReader(new File(source));
            BufferedReader bfr = new BufferedReader(fr);

            FileWriter frout = new FileWriter(new File(out));
            BufferedWriter bfrout = new BufferedWriter(frout);

            char[] ss = new char[1024];
            int nbr = 0;
            while (bfr.ready() && ((nbr = bfr.read(ss, 0, ss.length)) != -1)) {
                bfrout.write(ss, 0, nbr);
                bfrout.flush();
            }

            bfrout.flush();
            fr.close();
            bfr.close();
            frout.close();
            bfrout.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.err.println(e.getMessage() + source);
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println(e.getMessage() + source);
            return false;
        }
        return true;
    }
}

Related

  1. copyFile(String source, String dest)
  2. copyFile(String src, String dst)
  3. copyFile(String src, String dst)
  4. copyFile(String srcFile, String dstFile)
  5. copyFile(String srcFileName, String destFileName)
  6. copyFileContentsIntoAnotherFile(String inputFileName, PrintWriter Out)
  7. copyFileFromJar(File jarFile, File targetFile, String sourceFilePath)
  8. copyFileLinewise(File inputFile, File outputFile)
  9. copyFileRecursivlyLinewise(File inDir, File outDir)