Esempio di StreamTokenizer

Autore: stefano.russo@unina.it Java

  1. public class StreamTokenApp {
  2. public static void main (String args[]) throws IOException {
  3.                                       new InputStreamReader(System.in));
  4. st.ordinaryChar('.');
  5. st.ordinaryChar('-');
  6. while (st.nextToken() != StreamTokenizer.TT_EOF) {
  7. switch(st.ttype) {
  8. case StreamTokenizer.TT_EOL:
  9. s = new String("EOL");
  10. break;
  11. case StreamTokenizer.TT_NUMBER:
  12. s = Double.toString(st.nval);
  13. break;
  14. case StreamTokenizer.TT_WORD:
  15. s = st.sval;
  16. break;
  17. default:
  18. s = String.valueOf((char)st.ttype); }
  19. System.out.println( "Token = "+s);}
  20. inStream.close();
  21. inData.close();}}