The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Re: BufferedReader

Posted by Brian Sanders on December 10, 2001 at 2:09 PM

Now this gives me some trouble, because i want to read one line (with readLine()) and subsequentially start to read a file over the InputStream.

Unfortunately, BufferedReader uses a fixed-size buffer. To read just one line from the underlying stream, do something like this:


InputStreamReader streamReader = new InputStreamReader(myInputStream);

StringBuffer firstString = new StringBuffer();
for (int c = streamReader.read(); c != '\n'; c = streamReader.read())
firstString.append(c);

This example assumes that the EOL character will always be \n. There is a little more to it otherwise.



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us