Re: StreamTokenizer

Discussion in 'Java' started by Sudsy, Jul 24, 2003.

  1. Sudsy

    Sudsy Guest

    Ian deSouza wrote:
    > How do I avoid having the stream tokenizer parse digits?

    <snip>

    > With a file containing:
    > 12&3124 23-0 0-12-32
    >
    > I would like tokens: 12&3124 and 23-0 and 0-12-32


    In that case, why not use StringTokenizer? Read the input file
    using a BufferedReader (use the readLine method) and then parse
    each line.
     
    Sudsy, Jul 24, 2003
    #1
    1. Advertising

  2. Sudsy

    Ian deSouza Guest

    Thanks for the suggestion, but things aren't necessarily line based,
    and I may switch (midstream) what I consider a token.

    Ian

    Sudsy <> wrote in message news:<>...
    > Ian deSouza wrote:
    > > How do I avoid having the stream tokenizer parse digits?

    > <snip>
    >
    > > With a file containing:
    > > 12&3124 23-0 0-12-32
    > >
    > > I would like tokens: 12&3124 and 23-0 and 0-12-32

    >
    > In that case, why not use StringTokenizer? Read the input file
    > using a BufferedReader (use the readLine method) and then parse
    > each line.
     
    Ian deSouza, Aug 1, 2003
    #2
    1. Advertising

  3. Sudsy

    Sudsy Guest

    Ian deSouza wrote:
    > Thanks for the suggestion, but things aren't necessarily line based,
    > and I may switch (midstream) what I consider a token.
    >
    > Ian


    I beg your parsnips. How about this?

    StreamTokenizer st = null;

    try {
    st = new StreamTokenizer( new FileReader(
    some_file ) );
    // turn off special numeric interpretation
    st.ordinaryChars( '0', '9' );
    // all printable characters are word characters
    st.wordChars( 33, 126 );
    // all control characters are whitespace as
    // is the space character
    st.whitespaceChars( 0, 32 );
    while( st.nextToken() != StreamTokenizer.TT_EOF )
    System.out.println( st.sval );
    }
    catch( Exception e ) {
    // handle the usual problems
    }
     
    Sudsy, Aug 2, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D. Lane
    Replies:
    1
    Views:
    2,498
    Dave Rathnow
    Jun 30, 2003
  2. John C. Bollinger

    Re: How does StreamTokenizer work

    John C. Bollinger, Jun 30, 2003, in forum: Java
    Replies:
    0
    Views:
    874
    John C. Bollinger
    Jun 30, 2003
  3. Ian deSouza

    Re: StreamTokenizer

    Ian deSouza, Aug 1, 2003, in forum: Java
    Replies:
    0
    Views:
    1,571
    Ian deSouza
    Aug 1, 2003
  4. JVarsoke
    Replies:
    1
    Views:
    1,541
    Dale King
    Oct 1, 2003
  5. Eric
    Replies:
    3
    Views:
    1,151
Loading...

Share This Page