Copy.java


Below is the syntax highlighted version of Copy.java from §1.5 Input and Output.


/******************************************************************************
 *  Compilation:  javac Copy.java
 *  Execution:    java Copy < file
 *  Dependencies: BinaryStdIn.java BinaryStdOut.java
 *  
 *  Reads in a binary file from standard input and writes it to standard output.
 *
 *  % java Copy < mandrill.jpg > copy.jpg
 *
 *  %  diff mandrill.jpg copy.jpg
 *
 ******************************************************************************/

public class Copy {

    public static void main(String[] args) {
        while (!BinaryStdIn.isEmpty()) {
            char c = BinaryStdIn.readChar();
            BinaryStdOut.write(c);
        }
        BinaryStdOut.flush();
    }
}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 14:12:12 EDT 2017.