All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.pdx.cs410J.core.WriteToFile Maven / Gradle / Ivy

The newest version!
package edu.pdx.cs410J.core;

import java.io.*;

/**
 * This program writes the arguments from the command line to a text
 * file.  It demonstrates the FileWriter class.
 */
public class WriteToFile {
  private static PrintWriter err;

  /**
   * The first argument is the file to write to.
   */
  public static void main(String[] args) {
    // Wrap a PrintWriter around System.err
    err = new PrintWriter(System.err, true);

    // Make a new FileWriter
    Writer writer;
    try {
      writer = new FileWriter(args[0]);

      // Write the command line arguments to the file
      for (int i = 1; i < args.length; i++) {
      	writer.write(args[i]);
      	writer.write('\n');
      }
    
      // All done
      writer.flush();
      writer.close();

    } catch (IOException ex) {
      err.println("** " + ex);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy