import java.io.*; /* Author: James Tam Version: Jan 21, 2013 External source code used: * Getting the command-line input * Reading from file * Converting the lines from file to numeric form. */ public class Guessing { public static void main(String [] args) throws Exception { FileReader fr = null; BufferedReader br = null; String filename = null; String lineFromFile = null; boolean finished = false; int num = -1; // JT: The first and only input to the program (after name of Java // file) must be the name of the input file. // the if (args.length != 1) System.out.println("Usage:java Guessing "); else { filename = args[0]; fr = new FileReader(filename); br = new BufferedReader(fr); lineFromFile = br.readLine(); // JT: Empty input file if (lineFromFile == null) { System.out.println("Empty input file: no guesses to play with"); finished = true; } else num = Integer.parseInt(lineFromFile); // JT, Non-empty input file: one stopping condition is when the // last line in the input file has been reached. while(finished == false) { // JT: Echo the data from file onscreen, actual program // needs to play the game. System.out.println(num); // JT: EOF reached lineFromFile = br.readLine(); if (lineFromFile == null) finished = true; else num = Integer.parseInt(lineFromFile); } } } }