...does this piece of code do what it's intended for:
First, <code>InputStream.toString()</code> (which is inherited from <code>Object</code>!) returns something like "<code>java.io.FileInputStream@23fc4bec</code>", NOT the content of the underlying file.
Calling read twice in the loop reads just every second byte, so the output really means:
<code> 97 - a
97 - a
105 - i
46 - .
105 - i
101 - e
110 - n
117 - u
83 - S
114 - r
97 - a
64 - @
51 - 3
99 - c
98 - b
99 - c</code>
Compare this with the output of <code>.toString()</code> and recognize...
That's how <code>read()</code> is used:
int b;
while (( b = stream.read()) != -1) {
// ... do something with b ...
}
No, never ever...Geri May 24, 2011 at 3:45 PM
...does this piece of code do what it's intended for: First, <code>InputStream.toString()</code> (which is inherited from <code>Object</code>!) returns something like "<code>java.io.FileInputStream@23fc4bec</code>", NOT the content of the underlying file. Calling read twice in the loop reads just every second byte, so the output really means: <code> 97 - a 97 - a 105 - i 46 - . 105 - i 101 - e 110 - n 117 - u 83 - S 114 - r 97 - a 64 - @ 51 - 3 99 - c 98 - b 99 - c</code> Compare this with the output of <code>.toString()</code> and recognize... That's how <code>read()</code> is used: int b; while (( b = stream.read()) != -1) { // ... do something with b ... }
Post your Comment