// let's write a program that prints all words from a file having a specified // length -- here we combine file input and interactive input. import java.util.*; import java.io.*; public class FileIO2 { public static void main(String [] args) throws IOException { // Set up all our I/O. BufferedReader input = new BufferedReader(new FileReader("coleridge.txt")); BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in)); // Get input: the length of words. System.out.print("What length of words would you like to see? "); int desiredLength = Integer.parseInt(kbd.readLine()); while(true) { String line = input.readLine(); if (line == null) break; StringTokenizer tokenizer = new StringTokenizer (line, " .!,;"); while (tokenizer.hasMoreTokens()) { String word = tokenizer.nextToken(); if (word.length() == desiredLength) System.out.println(word); } } input.close(); } }