// StreamTokenizerExample.java import java.io.*; class StreamTokenizerExample { public static void main(String[] args) { StreamTokenizer st = new StreamTokenizer( new BufferedReader( new InputStreamReader(System.in))); // Include the following line if you want end-of-line tokens st.eolIsSignificant(true); // Include the following line if you want SPACES in your string values // st.wordChars(32,32); // Include the following line if you want TABS in your string values // st.wordChars('\t','\t'); while (true) { int token; try { token = st.nextToken(); } catch (Exception e) { System.out.println(" ** I/O Exception"); break; } if (token == st.TT_EOF) { System.out.println(" ** eof"); break; } else if (token == st.TT_EOL) System.out.println(" ** newline"); else if (token == st.TT_NUMBER) System.out.println(" ** number: " + st.nval); else if (token == st.TT_WORD) System.out.println(" ** string: " + st.sval); else System.out.println(" ** unknown token: " + token); } } }