Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下代码总是生成大小为 1 的字节数组,有什么想法吗?
FileHeader fh = (FileHeader) packageFile.getFileHeaders().get(1); InputStream inputStream = packageFile.getInputStream(fh); byte[] bytes=new byte[inputStream.available()];
zip文件很好!
你能指望什么?也许你的理解available()不正确。该方法返回一个估计值,但取决于实现。
available()
来自文档;
请注意,虽然 InputStream 的某些实现会返回流中的字节总数,但许多不会。使用此方法的返回值来分配旨在保存此流中所有数据的缓冲区是不正确的。
看起来您正在定义一个缓冲区bytes来读取数据。
bytes