aspose file tools*
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

Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 8713

You can read a line from a StringBuffer using Readers:

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[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
Similar Threads
Pls Help on read the log file BACKWARd?
why it is giving errors example?
An exception in java-XML --kindly clarify-urgent
OutOfMemoryError: Java heap space error when exporting more than 65MB file