File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Get a single line from a String Buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Get a single line from a String Buffer" Watch "Get a single line from a String Buffer" New topic

Get a single line from a String Buffer

Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
How do i get a single line from a string buffer that has already been created?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

How do you know the Stringbuffer contains lines at all?
If your buffer looks like this:

text2 seems to be a line, but text1 and text3 could be a part of a line.
For a buffer containing no NewLine at all, would you say the whole buffer is a line on it's own?

So do we have three lines here?:
Joe Ess

Joined: Oct 29, 2001
Posts: 9167

You can read a line from a StringBuffer using Readers:

[How To Ask Questions On JavaRanch]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
That gets you the first line.

You may need to create the BufferedReader as shown and then call readLine() on it until you get the line you want.

Mike Gershman
SCJP 1.4, SCWCD in process
I agree. Here's the link:
subject: Get a single line from a String Buffer
It's not a secret anymore!