Solved

StreamTokenizer separators...

Posted on 2000-05-16
3
345 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
  • 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
micro services vs rest web services 16 107
GUI builder for Eclipse? 8 37
Spring Framework HTTPSession management 1 36
printf performancy 11 43
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 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…
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.

831 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