Solved

StreamTokenizer separators...

Posted on 2000-05-16
3
351 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 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

635 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