Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > excuse me,why i cannot read the complete HTML file...thank you

Reply
Thread Tools

excuse me,why i cannot read the complete HTML file...thank you

 
 
mike
Guest
Posts: n/a
 
      09-10-2004
the followings is my code:

InputStream in = outSocket.getInputStream();
InputStreamReader insr = new InputStreamReader(in);
String myencode=insr.getEncoding();
int available_length=in.available();
int available_length_char=available_length/2;
char cbuf[] = new char[available_length_char];
System.out.println(available_length);
System.out.println(myencode);
insr.read(cbuf,0,available_length_char);
in.close();
insr.close();

i want to read the data in the InputStream and save the data in the cbuf array,
but by my code,i cannot read the complete HTML file,i print out the cbuf
and cannot see the HTML file end indicator:"</html>"

any suggestion is welcome thank you
 
Reply With Quote
 
 
 
 
KC Wong
Guest
Posts: n/a
 
      09-10-2004
<snip>

The cause is that available() call only returns the number of bytes you can
read before blocking. It does not mean that's the end of the data... it is
possible that not all the data have arrived when you call read().

Use a while loop, and read until you get a -1 (which indicates end of
stream).


 
Reply With Quote
 
 
 
 
Vincent Cantin
Guest
Posts: n/a
 
      09-10-2004
> The cause is that available() call only returns the number of bytes you
can
> read before blocking. It does not mean that's the end of the data... it is
> possible that not all the data have arrived when you call read().
>
> Use a while loop, and read until you get a -1 (which indicates end of
> stream).


Precision : available() will never return -1.
The minimum it usually returns is 0.


 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a
 
      09-10-2004
Vincent Cantin wrote:

>> The cause is that available() call only returns the number of bytes you

> can
>> read before blocking. It does not mean that's the end of the data... it
>> is possible that not all the data have arrived when you call read().
>>
>> Use a while loop, and read until you get a -1 (which indicates end of
>> stream).

>
> Precision : available() will never return -1.
> The minimum it usually returns is 0.


The prior poster is not suggesting the use of available() at all. He
suggests actually reading characters until -1 is returned, indicating end
of file.

--
Paul Lutus
http://www.arachnoid.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT: Yet another excuse for you to call me crazy... The Message [00000-0000-0000-0000] MCSE 25 04-21-2007 01:40 PM
Pls excuse if you consider this off-topic. Conceptual artists seek programmers here. M_Mann@artenom.com C++ 3 07-12-2006 09:01 PM
Pls excuse if you consider this off-topic. Conceptual artists seek programmers here. M_Mann@artenom.com C Programming 8 07-10-2006 04:07 PM
Pls excuse if you consider this off-topic. Conceptual artists seek programmers here. M_Mann@artenom.com Python 0 07-08-2006 11:58 AM
Complete name for NG: excuse me for the FAQ mrzac Firefox 5 12-27-2003 06:08 AM



Advertisments