Browse - Programming Tips - How can I use StreamTokenizer on a string?

Date: 2013feb5
Language: Java

Q.  How can I use StreamTokenizer on a string?

A. Use ByteArrayInputStream to make an InputStream
and then convert that into a Reader:

String s = "String I want to parse"; InputStream is = new ByteArrayInputStream(s.getBytes()); Reader r = new BufferedReader(new InputStreamReader(is)); StreamTokenizer tokenizer = new StreamTokenizer(r); // You can now use tokenizer