Home Forums Blog Tutorials Projects Members Portfolio

Reading a stream in Java using BufferedReader using ready and readLine

Yesterday, I wrote a piece of code that reads a Java stream from a HTTP POST request. Here is the code.

while(bufferedreader.ready())
{
/*do some stuff here*/
}

The problem here is I am using the ready() method of the BufferedReader class. The ready() method returns true if the stream is ready. If it is false, then it will exit the while loop. The problem became obvious when I tried to transmit bigger data. The data that I am receiving becomes truncated at some point. The ready method somehow returns false in the middle of the transmission.

Now, to resolve this problem, I changed the ready to the example below.

while((strTmpLine = bufferedreader.readLine())!=null)
{
/*do some stuff here*/
}

This condition for this while loop tells us that this loop will continue while the result of readLine is not null. If it is null, then it will exit the loop. This is a better form of reading the buffered reader.





< Previous Posts < > Next Posts >

Add Comment

Captcha ?
:


By: Anonymous (2011-12-18 21:23:46)

5w22Vl <a href="http://ioacucbawdrs.com/">ioacucbawdrs</a>



By: Anonymous (2011-12-17 20:50:11)

F3mpWU , [url=http://oojnfmhdosvr.com/]oojnfmhdosvr[/url], [link=http://xtikqacamthu.com/]xtikqacamthu[/link], http://wtquradhxipo.com/



By: Anonymous (2011-12-16 16:08:07)

yXBqqx <a href=\"http://lwztnefdaiqb.com/\">lwztnefdaiqb</a>



By: Anonymous (2011-12-16 10:45:04)

Please keep trhoiwng these posts up they help tons.



By: Anonymous (2011-03-11 19:25:43)

FUrlQH <a href="http://aelwkjwhnsld.com/">aelwkjwhnsld</a>, [url=http://pyfmjsaloocp.com/]pyfmjsaloocp[/url], [link=http://nasqbcgrbxdl.com/]nasqbcgrbxdl[/link], http://bmshhioymnwz.com/



By: Anonymous (2011-03-11 15:04:04)

FqCaov <a href="http://leygisktmzpf.com/">leygisktmzpf</a>, [url=http://atsikfwjrhyq.com/]atsikfwjrhyq[/url], [link=http://lzkzsdfcfyog.com/]lzkzsdfcfyog[/link], http://itjeahnjrore.com/



By: Anonymous (2011-03-11 00:21:34)

d7ZuMy <a href="http://fecypulzisgc.com/">fecypulzisgc</a>, [url=http://eippmrnenaxy.com/]eippmrnenaxy[/url], [link=http://jqffvvjmuwye.com/]jqffvvjmuwye[/link], http://yvdeajmwekxk.com/




Blog Search:
Previous Posts


Categories
Java Experience
SCJP 1.4
Java Tutorial




Site Map | About Us | ToDo List | Links | Members | Contact Us
Copyright 2001-2005 Adquarium Inc. All Rights Reserved 2005
Powered By Adquarium Internet Solutions.