Java FileReader 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 boolean copyFile(String input, String output) 

Method Source Code


//package com.java2s;
import java.io.File;

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

public class Main {
    public static boolean copyFile(String input, String output) {
        File inputFile = new File(input);
        File outputFile = new File(output);

        try {/*w  w  w . j av a2 s .  c o m*/
            FileReader in = new FileReader(inputFile);
            FileWriter out = new FileWriter(outputFile);

            int c;

            while ((c = in.read()) != -1)
                out.write(c);

            in.close();
            out.close();

        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

        return true;

    }

    public static boolean copyFile(File input, File output) {
        try {
            FileReader in = new FileReader(input);
            FileWriter out = new FileWriter(output);

            int c;

            while ((c = in.read()) != -1)
                out.write(c);

            in.close();
            out.close();

        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

        return true;

    }
}

Related

  1. copyFile(File inputFile, File outputFile)
  2. copyFile(File source, File destination)
  3. copyFile(String fromFilePath, String toFileDir)
  4. copyFile(String inputName, String destination)
  5. copyFile(String sourceFileName, String targetFileName)
  6. copyFile(String srcFileName, String dstFileName)
  7. copyFileToDir(File inputFile, File outputDir)