Skip to content

Instantly share code, notes, and snippets.

@atomicpages
Created February 2, 2016 07:05
Show Gist options
  • Save atomicpages/5332bac39e7c77101c46 to your computer and use it in GitHub Desktop.
Save atomicpages/5332bac39e7c77101c46 to your computer and use it in GitHub Desktop.
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment