import java.io.*; import java.util.Scanner; public class FormatText1 { public static String[] words = new String[10000]; // Hold words in input file public static int numWords; // Count # words in input /* =========================================================== readInput(in, w): read words from input "in" into array w and return the #words read ============================================================ */ public static int readInput( Scanner in, String[] w ) { int nWords = 0; while ( in.hasNext() ) { w[nWords] = in.next(); // Read next string (word) nWords++; // Count # words AND use next // array element for next word } return( nWords ); } public static void main(String[] args) throws IOException { if ( args.length == 0 ) { System.out.println( "Usage: java FormatText1 inputFile"); System.exit(1); } File myFile = new File( args[0] ); // Open file Scanner in = new Scanner(myFile); // Make Scanner obj with opened file /* ---------------------------- Read input from data file ---------------------------- */ numWords = readInput( in, words ); /* ------------------------------- Check ------------------------------- */ for ( int i = 0 ; i < numWords; i++ ) System.out.println( words[i] ); } }