Stream Tokenizer in Java: Trying to implement
<p>I am new to Java and learning it. I have written a code to take user input and tokenize it. It compiles successfully but when run produces '-3' as o/p.</p>

<pre><code>import java.io.*;


public class TokenTester{

    public static void main(String[] arguments){
    String name;
    StreamTokenizer token;
    BufferedReader reader;
    reader = new BufferedReader(new InputStreamReader(System.in));

     try{
            System.out.println("Enter a String  ");
            name = reader.readLine();
            System.out.println(name);
            token=new StreamTokenizer((new StringReader(name)));
           //token=new StreamTokenizer(name);
            // Using new StreamTokenizer(name) throws error
            //error: no suitable constructor found for StreamTokenizer(String)
             while(token.nextToken()!= token.TT_EOF)
            {
             System.out.println(token.nextToken());
                }
            }
        catch (IOException ioe){
             System.out.println("An unexpected error occured.");
        }

        }
    }
</code></pre>

<p>Also when I use  new StreamTokenizer(name) throws error
"error: no suitable constructor found for StreamTokenizer(String)"</p>

<p>When I use while(token.nextToken()!= token.TT_EOF)
it shows infinite loop is -1 as o/p</p>

<p>Below code works absolutely fine:</p>

<pre><code>import java.util.StringTokenizer;

 class TokenTester {

 public static void main(String[] arguments) {
 StringTokenizer st1, st2;

 String quote1 = "VIZY 3 -1/16";
 st1 = new StringTokenizer(quote1);
 System.out.println("Token 1: " + st1.nextToken());
 System.out.println("Token 2: " + st1.nextToken());
 System.out.println("Token 3: " + st1.nextToken());

 String quote2 = "NPLI@9 27/32@3/32";
 st2 = new StringTokenizer(quote2, "@");
 System.out.println("\nToken 1: " + st2.nextToken());
System.out.println("Token 2: " + st2.nextToken());
System.out.println("Token 3: " + st2.nextToken());
 }
 }
</code></pre>

<p>I am not able to figure out the issue in my code.
Please guide.</p>

<p>I have refered:</p>

<pre><code>http://tutorials.jenkov.com/java-io/streamtokenizer.html
http://www.java-samples.com/showtutorial.php?tutorialid=397
http://docs.oracle.com/javase/7/docs/api/
</code></pre>

<p>Thanks
Gaurav</p>
