A problem regarding streams

  • Thread starter Christian H. Mosveen
  • Start date
C

Christian H. Mosveen

Greetings.
I am taking in a stream and putting it in a BufferedReader. Now, I want to
traverse the stream looking for a line starting
with a given string. Then I'd put the line in a String, and process it
later.
I have sniffed around the StreamTokenizer class, but it didn't make me
much wiser.
Can anyone point me in the right direction?

Thank you,
Christian H. Mosveen.
 
S

Shripathi Kamath

Christian H. Mosveen said:
Greetings.
I am taking in a stream and putting it in a BufferedReader. Now, I want to
traverse the stream looking for a line starting
with a given string. Then I'd put the line in a String, and process it
later.
I have sniffed around the StreamTokenizer class, but it didn't make me
much wiser.
Can anyone point me in the right direction?


You appear to be on a right track, what specific issues are you
encountering?
 
G

Gordon Beaton

I am taking in a stream and putting it in a BufferedReader. Now, I
want to traverse the stream looking for a line starting with a given
string. Then I'd put the line in a String, and process it later. I
have sniffed around the StreamTokenizer class, but it didn't make me
much wiser. Can anyone point me in the right direction?

Based on your description, you don't need to tokenize anything.

You can read one whole line at a time with the BufferedReader. You
don't need to "put the line in a String", it already *is* a String.
For each line, use String.startsWith() to find the lines that match
your criteria.

/gordon
 
S

Steve Horsley

Greetings.
I am taking in a stream and putting it in a BufferedReader. Now, I want to
traverse the stream looking for a line starting
with a given string. Then I'd put the line in a String, and process it
later.
I have sniffed around the StreamTokenizer class, but it didn't make me
much wiser.
Can anyone point me in the right direction?

Thank you,
Christian H. Mosveen.

How about a loop with

String s = byBufferedReader.readLine();
int index = s.indexOf(searchString);
if(index >= 0) {...

until you get a line with the string in it?

Steve
 
C

Christian H. Mosveen

På 31 Oct 2003 21:34:55 +0100, skrev Gordon Beaton <[email protected]>:

------8<------------
For each line, use String.startsWith() to find the lines that match
your criteria.

/gordon

Thank you, this worked like a charm. I really need to get more aware of
all the built-in String methods.

Christian.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top