Copy.java


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


/******************************************************************************
 *  Compilation:  javac-introcs Copy.java
 *  Execution:    java-introcs Copy < file
 *  Dependencies: BinaryStdIn.java BinaryStdOut.java
 *
 *  Reads in a binary file from standard input and writes it to standard output.
 *
 *  % java-introcs 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–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:14:17 EDT 2022.