Skip to content

Instantly share code, notes, and snippets.

@atomicpages
Created February 2, 2016 07:05
Show Gist options
  • Select an option

  • Save atomicpages/5332bac39e7c77101c46 to your computer and use it in GitHub Desktop.

Select an option

Save atomicpages/5332bac39e7c77101c46 to your computer and use it in GitHub Desktop.

Revisions

  1. atomicpages created this gist Feb 2, 2016.
    39 changes: 39 additions & 0 deletions Prog3b.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    import java.util.Scanner;
    import java.io.PrintWriter;
    import java.io.File;

    public class Prog3b {

    public static void main(String[] args) {
    System.out.println("Program 3, Dennis Thompson, masc001");
    if(args.length != 2) {
    System.err.println("Usage: java Prog3b infileName outfileName");
    System.exit(1);
    }

    Scanner handle = null;
    PrintWriter out = null;

    try {
    handle = new Scanner(new File(args[0]));
    } catch(java.io.FileNotFoundException e) {
    System.err.println(e.getMessage());
    System.exit(1);
    }

    try {
    out = new PrintWriter(System.getProperty("user.dir") + "/" + args[1], "UTF-8");
    while(handle != null && handle.hasNextLine()) {
    out.println(handle.nextLine().replace(' ', ','));
    }
    out.close();
    } catch(java.io.IOException e) {
    System.err.println(e.getMessage());
    System.exit(1);
    } finally {
    out.close();
    handle.close();
    }
    }

    }