InputStream missing CR

Hellow

I'm using InputStream

for(;;){

try{

int cbToRead = input.available()

if (cbToRead<1) cbToRead=20;

byte b[];

b = new byte[cbToRead];

input.read(b);

System.out.println( new String(b) );

}

}catch (Exception e) {

System.out.printlnt(e.getMessage());

e.printStackTrace();

}

its work fine but after fiew loops it got an Exception

missing CR

what is CR

[466 byte] By [Ori-Gila] at [2007-11-27 7:30:46]
# 1
Usually it means "Carriage Return", i.e. ASCII code 13. Posting the complete error message/stack trace might return more information.
quittea at 2007-7-12 19:11:01 > top of Java-index,Java Essentials,Java Programming...
# 2

BTW most of this code is (a) incorrect usage of available(); (b) incorrect use of read(); (c) a waste of computation time; and (d) a waste of memory and GC.

Try this:

byte[] buffer = new byte[8192];

int count;

while ((count = input.read(buffer)) > 0)

{

String s = new String(buffer, 0, count);

System.out.println(s);

}

plus your exception handling.

ejpa at 2007-7-12 19:11:01 > top of Java-index,Java Essentials,Java Programming...
# 3
> byte[] buffer = new byte[8192];why 8192? is it the most effective buffer length for file?
j_shadinataa at 2007-7-12 19:11:01 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi its make it wores

sun.net.www.http.ChunkedInputStream.processRaw(ChunkedInputStream.java:378)

sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:545)

sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:582)

sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:669)

java.io.FilterInputStream.read(FilterInputStream.java:116)

sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2364)

sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2359)

test.client.TestClient.receiveMesages(TestClient.java:251)

test.client.TestClient.access$2(TestClient.java:224)

test.client.TestClient$3.run(TestClient.java:135)

Ori-Gila at 2007-7-12 19:11:01 > top of Java-index,Java Essentials,Java Programming...
# 5
Is that part of an exception stack trace? Where's the rest of it?And why are you reaidng bytes and printing Strings? Are these things lines? in which case you should be using BufferedReader.readLine().
ejpa at 2007-7-12 19:11:01 > top of Java-index,Java Essentials,Java Programming...
# 6
Hi I don't get the streem from file i'm geting it from URL
Ori-Gila at 2007-7-12 19:11:01 > top of Java-index,Java Essentials,Java Programming...
# 7
So? That makes precisely diddly-squat difference.
ejpa at 2007-7-12 19:11:01 > top of Java-index,Java Essentials,Java Programming...