FileCopy.java Source code

Java tutorial

Introduction

Here is the source code for FileCopy.java

Source

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

class FileCopy {

    public static void main(String args[]) throws Exception {

        FileReader fr = new FileReader(args[0]);

        // Create a file writer
        FileWriter fw = new FileWriter(args[1]);

        // Read and copy characters
        int i;
        while ((i = fr.read()) != -1) {
            fw.write(i);
        }
        fw.close();

        fr.close();
    }
}