Community
Participate
Working Groups
If I write the following code... int len = 0; byte[] buf = new byte[BUFFER]; while ((len = is.read(buf, 0, BUFFER)) != -1) { } The first reference of len is underlined in yellow and the message is: "The local variable len is never read" If I try to write the code above like this: byte[] buf = new byte[BUFFER]; while ((int len = is.read(buf, 0, BUFFER)) != -1) { } Then I get a compile error: Multiple markers at this line: len cannot be resolved syntax error on token int, delete this token Ideally, I'd love to be able to write the code above in such a way as to produce no warnings or errors. =) Apologies if I have filed this under the wrong product/component... it's difficult to find the correct values without really understanding how this organization is defined. thanks, jon
In this code: int len = 0; byte[] buf = new byte[BUFFER]; while ((len = is.read(buf, 0, BUFFER)) != -1) { } You actually don't read the variable len. So if you want to remove the warning, why don't you simply write: byte[] buf = new byte[BUFFER]; while (is.read(buf, 0, BUFFER) != -1) { } but I would say the right answer is probably to use the value of len in the while block. Otherwise you are simply reading from an input stream without ever doing anything with the data. Ok to close?
Good point. closing! =) thanks for the quick response.