001package algs11; 002import stdlib.*; 003/* *********************************************************************** 004 * Compilation: javac Cat.java 005 * Execution: java Cat input0.txt input1.txt ... output.txt 006 * Dependencies: In.java Out.java 007 * 008 * Reads in text files specified as the first command-line 009 * parameters, concatenates them, and writes the result to 010 * filename specified as the last command line parameter. 011 * 012 * % more in1.txt 013 * This is 014 * 015 * % more in2.txt 016 * a tiny 017 * test. 018 * 019 * % java Cat in1.txt in2.txt out.txt 020 * 021 * % more out.txt 022 * This is 023 * a tiny 024 * test. 025 * 026 *************************************************************************/ 027 028public class Cat { 029 030 public static void main(String[] args) { 031 //args = new String[] { "data/ex1.txt", "data/ex2.txt", "data/ex3.txt", "data/ex4.txt", "/tmp/out.txt" }; 032 args = new String[] { "data/in1.txt", "data/in2.txt", "/tmp/out.txt" }; 033 034 Out out = new Out(args[args.length - 1]); 035 for (int i = 0; i < args.length - 1; i++) { 036 In in = new In(args[i]); 037 String s = in.readAll(); 038 out.println(s); 039 in.close(); 040 } 041 out.close(); 042 StdOut.format ("Output is in file \"%s\"", args[args.length - 1]); 043 } 044 045}