public class Application {
public static void main(String[] args) throws IOException {
String path = "file.zip";
try (FileInputStream inputStream = new FileInputStream(Paths.get(path).toFile())) {
readZipInputStream(
inputStream,
(entry, outputStream) -> {
System.out.println(entry.getName());
System.out.println("--------------------------------");
System.out.println(outputStream.toString());
System.out.println("--------------------------------");
}
);
}
}
}
将打印三个.txt文件的内容:
1.txt
--------------------------------
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
--------------------------------
2.txt
--------------------------------
- Integer vel sem consectetur, ullamcorper leo quis, consequat mauris.
- Nulla efficitur sapien at velit fermentum condimentum.
- Vestibulum elementum nulla ut ipsum tempus, ut molestie sem sollicitudin.
--------------------------------
3.txt
--------------------------------
Morbi tincidunt ornare mi. Sed id risus tortor. Interdum et malesuada
fames ac ante ipsum primis in faucibus. Pellentesque tincidunt,
nulla a interdum porta, orci elit ultricies leo, in maximus orci
tortor pulvinar est. Curabitur eget fermentum risus. Vestibulum euismod
convallis eros, nec blandit neque blandit at.
--------------------------------
2条答案
按热度按时间3lxsmp7m1#
如果要读取嵌套的.zip文件,可以尝试使用
ZipInputStream
(就像已经提到的)检查一下ZipEntry
(s) 也是一个*.zip文件,在这种情况下,它可以作为下一个.zip文件递归读取。比如:例如,有一个结构如下的zip文件:
以及使用
readZipInputStream
功能如下:将打印三个.txt文件的内容:
7hiiyaii2#
java类java.util.zip.zipinputstream允许您将数据从zip存档读取到字节数组中。