/* Tokenize.java CIS 160 David Klick 2004-09-22 Demonstrates String and StringTokenizer methods as well as reading from a file. */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; public class Tokenize { public static void main(String[] args) throws IOException { String line, word, bigWord = ""; int max = 0, wordCount=0, lineCount = 0; BufferedReader in = new BufferedReader(new FileReader("javahead.txt")); line = in.readLine(); while (line != null) { lineCount++; StringTokenizer tkn = new StringTokenizer(line, "\t\r\n\f\" -!?.,()&"); while (tkn.hasMoreTokens()) { word = tkn.nextToken(); wordCount++; int len = word.length(); if (len > max) { max = len; bigWord = word; } } line = in.readLine(); } in.close(); System.out.println("Line count: " + lineCount); System.out.println("Word count: " + wordCount); System.out.println("Max word size: " + max); System.out.println("Longest word: " + bigWord); } }