import java.io.*; import java.util.*; /******************************************************************************/ /** Candidate main program * * This program does the usual open and close of files using the DABUtils methods, * and then it reads the file into an ArrayList and echoes the ArrayList to the * console. * * @author Duncan Buell * * written: 29 March 2008 */ public class Main1 { public static void main(String[] args) { String inFileName = null; String outFileName = null; String readString = ""; ArrayList candidateList = new ArrayList(); Scanner console = new Scanner(System.in); Scanner inDataFile = null; PrintWriter outDataFile = null; /******************************************************************************/ /** Boilerplate: open the input and output files and echo that information * to the console. **/ System.out.printf("Enter input file name: "); inFileName = console.next(); System.out.printf("Enter output file name: "); outFileName = console.next(); System.out.printf("Input file name is: %s%n",inFileName); System.out.printf("Output file name is: %s%n",outFileName); inDataFile = DABUtils.ScannerOpen(inFileName); System.out.printf("Input file '%s' opened, continue%n",inFileName); outDataFile = DABUtils.PrintWriterOpen(outFileName); System.out.println("Output file '" + outFileName + "' opened, continue"); /******************************************************************************/ /** Read in the candidate file one complete line at a time and add the lines * to an ArrayList. **/ while(inDataFile.hasNextLine()) { readString = inDataFile.nextLine(); candidateList.add(readString); } // while(inDataFile.hasNextLine()) System.out.println("File input processed"); /******************************************************************************/ /** Echo the data **/ outDataFile.printf("%nThe entire list of candidates is%n"); for(int i = 0; i < candidateList.size(); ++i) { outDataFile.printf("%2d %s%n",i,candidateList.get(i).toString()); } /******************************************************************************/ /** Close up and go home **/ inDataFile.close(); outDataFile.flush(); outDataFile.close(); System.out.printf("File processed, terminate%n"); } // public static void main(String[] args) } // public class Main1