Solved

StreamTokenizer separators...

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Custom Java Application connects to database: Which one of the 20? 4 58
jboss 7.1 start up error 1 84
how to debug htl and js pages 8 80
Html split(text) 2 49
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

738 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