Java BufferedReader Copy copyFileLinewise(File inputFile, File outputFile)

Here you can find the source of copyFileLinewise(File inputFile, File outputFile)

Description

Copies one file linewise to another file.

License

Open Source License

Parameter

Parameter Description
inputFile input file (that shall be copied)
outputFile destination file

Exception

Parameter Description
IOException thrown if reading or writing has failed

Declaration

public static void copyFileLinewise(File inputFile, File outputFile) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    /**/*from w  w  w  . j  a v  a2 s  .c om*/
     * Copies one file linewise to another file.
     *
     * @param inputFile input file (that shall be copied)
     * @param outputFile destination file
     * @throws IOException thrown if reading or writing has failed
     */
    public static void copyFileLinewise(File inputFile, File outputFile) throws IOException {
        try {
            BufferedReader r = new BufferedReader(new FileReader(inputFile));
            BufferedWriter w = new BufferedWriter(new FileWriter(outputFile));

            String line;
            while ((line = r.readLine()) != null) {
                w.write(line);
                w.newLine();
            }

            w.close();
            r.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. copyFile(String srcFile, String dstFile)
  2. copyFile(String srcFileName, String destFileName)
  3. copyFile2(String source, String out)
  4. copyFileContentsIntoAnotherFile(String inputFileName, PrintWriter Out)
  5. copyFileFromJar(File jarFile, File targetFile, String sourceFilePath)
  6. copyFileRecursivlyLinewise(File inDir, File outDir)
  7. copyFileTextMode(String source, String destination)
  8. copyFileWithAppend(File source, File destination)