工作代码:
InputStream is = zipFile.getInputStream(zipArchiveEntry);
BufferedReader br = new BufferedReader(new InputStreamReader(zis));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
不工作的代码
InputStream is = zipFile.getInputStream(zipArchiveEntry);
ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
if(zis.canReadEntryData(zipArchiveEntry)) {
// Start
BufferedReader br = new BufferedReader(new InputStreamReader(zis));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
想法不是从 InputStream 中读取,而是尝试从 InputStream 创建 ZipArchiveInputStream,以便我可以利用 canReadEntryData() 方法。canReadEntryData() 工作得很好。它对普通文件返回 true,但我无法从 ZipArchiveInputStream 读取内容。
请帮忙。请指出我哪里出错了。