开发者

Working with ZipInputStream object, how can available() return a 1 but read return a -1?

开发者 https://www.devze.com 2023-03-26 15:57 出处:网络
Guys here is the relevant code... ZipInputStream zis = new ZipInputStream(zip.getInputStream(ze)); System.out.println(zis.available());

Guys here is the relevant code...

ZipInputStream zis = new ZipInputStream(zip.getInputStream(ze));
System.out.println(zis.available());
int count = zis.read(data,0,buffer);
System.out.println(count);

I continually get this as output... 1 -1

Now its my understandi开发者_Python百科ng that a 1 for available means it isn't at the end of the file and -1 returned from read means it is the end of the file. How can they both be true?


It's only an 'estimate': see the Javadoc. Presumably in this case it is intended to signify that you should do a read to collect the EOS indication. There are very few correct uses of available() and I doubt that this is one of them.


check if the value of 'buffer' passed to read method is less than or equal to 0 ?

0

精彩评论

暂无评论...
验证码 换一张
取 消