Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

StreamTokenizer separators...

Posted on 2000-05-16
3
Medium Priority
?
354 Views
Last Modified: 2012-06-27
I would like to know how to set to which separators the StreamTokenizer will "react". It is easy to set separatorst for StringTokenizer but it doesn't work with StreamTokenizer in that way.
0
Comment
Question by:ssdjgru1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
Laminamia063099 earned 400 total points
ID: 2814404
If you want to use simple delimiters, the following call can be used:
StreamTokenizer st = new StreamTokenizer(new
                                         BufferedInputStream(is,4000));
st.whiteSpace('|','|');

That would specify that the | character is the delimiter.  Any other delimiter can be added as such.

Drop a comment if you need mor help :)

Laminamia :)
0
 

Author Comment

by:ssdjgru1
ID: 2814815
hmm...there is no whiteSpace method in java.io.StreamTokenizer class.
There is whitespaceChars(int,int),void method  but I don't know how to use it.
0
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2815414
Oops.  Sorry that's the one I meant.  the whitespaceChars(int, int) method allows you to specify a range of characters that are considered to be whitespace (whitespace characters that you specify are your tokens.)

The following code:

            StreamTokenizer st = new StreamTokenizer(new BufferedReader(new FileReader("B.java")));
            st.whitespaceChars('|','|');

creates a StreamTokenizer that considers the characters from '|' to '|' (i.e. just '|') to be the only tokens in the StreamTokenizer.  That is how you set a token.

Use resetSyntax to reset the Tokenizer so that everything is considered "ordinary" (i.e. no tokens) and then set your own tokens using the whitespaceChars.

It does say that it takes int's, but by passing it characters, you are passing it the UNICODE value for those characters.

Good luck, drop a note if I'm still confusing :)

Laminamia :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question