Reading strings using BufferedReader.readLine() is too slow



I have the following code for reading a string from an input stream:

BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));

reply = new String();
String reply_now;

while ((reply_now = in.readLine()) != null) {
reply += reply_now;
}
in.close();

The problem is it's too slow and takes too much CPU time because, as I
guess, it performs too many additions with strings and I can't find
any alternative way of reading streams - reliable and not using
deprecated methods. How can I read text from a stream in bigger
portions than lines?

.



Relevant Pages

  • Re: Reading a Bitstream
    ... I looked at the array module and can't find what I'm looking for. ... I have a string, and ... I read fields from the bit stream, ... all suited to reading a bit stream. ...
    (comp.lang.python)
  • Re: c++ string stuff
    ... > I'm reading lines from a file and then reading off a value from the ... > One for the file stream, 2 for the line of text and one for the string ... to have a fairly common misunderstanding about eof. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: HLALib
    ... string buffers, and also "static dynamic strings", eg. static string ... ;function returns after reading one line, which can be less than size ... from any type of stream, so they never should access more than needed. ... line, stores it in buffer, and text parsing routine never reads more ...
    (alt.lang.asm)
  • Re: Easy question but I cant seem to get it to work
    ... BufferedReader br = new BufferedReader; ... return returnText; ... Reading a whole file into a string is dangerous, what if the whole file is 2GB long? ... I always just loop through reading each line and appending to a StringBuffer until readLine is null. ...
    (comp.lang.java.help)
  • Re: A problem regarding streams
    ... > I am taking in a stream and putting it in a BufferedReader. ... > want to traverse the stream looking for a line starting with a given ... Then I'd put the line in a String, ... You can read one whole line at a time with the BufferedReader. ...
    (comp.lang.java.programmer)