import java.io.*;

/**
 * Opens the file given by the command line argument and appends all other
 * command line arguments on a new line in that file.
 *
 * @author Zach Tomaszewski
 * @version 11 Nov 2008
 */
public class FileAppender {

  public static void main(String[] args) {
    if (args.length == 0) {
        //incorrect usage, so give usage message
        System.out.println("No filename specified on command line.\n");
        System.out.println("Usage: java FileAppender filename [arg2 arg3]\n");
        System.out.println("This program opens filename and " +
                           "appends all other args to that file.");
    }else {
      try {
        //open fileout for appending
        PrintWriter fileout = new PrintWriter(new FileWriter(args[0], true));
        for (int i = 1; i < args.length; i++) {
          //write all other args to file (with space between)
          fileout.print(args[i] + " ");
        }
        fileout.println(); //end line in file
        fileout.close();
      }catch (IOException ioe) {
        System.out.println("Could not write to file: " + ioe.getMessage());
      }
    }
  }

}
