我想解析一个.zip文件。该文件包含一个文件夹,而该文件夹又包含多个文件。我希望读取所有文件,但不需要将.zip文件写入磁盘。我有以下代码:
zipFile = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while(entries.hasMoreElements()){
ZipEntry entry = entries.nextElement();
InputStream stream = zipFile.getInputStream(entry);
InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
Scanner inputStream = new Scanner(reader);
inputStream.nextLine();
while (inputStream.hasNext()) {
String data = inputStream.nextLine(); // Gets a whole line
String[] line = data.split(SEPARATOR); // Splits the line up into a string array
}
inputStream.close();
stream.close();
}
zipFile.close();
问题在于这仅适用于文件直接存储在.zip文件中时才有效。我应该如何修改我的代码,以便在.zip文件中的文件位于文件夹中时也能正常工作?