title: Using StreamTokenizer to read a structured file
body: <p>If I have a file with some structure to it:</p>
  
  <pre><code>type
  2
  0 0 name
  100 100 name
  1
  1 2 name name
  </code></pre>
  
  <p>How can I use a <code>StreamTokenizer</code> to process this file? Is the only way the procedural approach?</p>
  
  <p>i.e.</p>
  
  <pre><code>StreamTokenizer st = new StreamTokenizer(new FileReader(filename));
  
  if (st.nextToken() != StreamTokenizer.TT_EOF) {
      st.nextToken();
      if (st.sval == "typea") {
          st.nextToken();
  
          int i = (int) st.nval;
          if (i &gt; 0) {
              while (i &gt; 0) {
                  // process node sets
              }
          }
      } else if (st.sval == "typeb") {
          st.nextToken();
  
          int i = (int) st.nval;
          if (i &gt; 0) {
              while (i &gt; 0) {
                  // process node sets
              }
          }
      }
  }
  </code></pre>
  
  <p>It's fine to skip if unexpected tokens exist.</p>