我想问是否可以访问和修改压缩在另一个压缩包中的压缩文件中的文本文件。
我知道我可以像这样使用 Java.nio FileSysten 访问该文件。在此示例中读取“sample.txt”文件中的所有行。
FileSystem fileSystem = FileSystems.newFileSystem(new URI("jar:file", "sample/path/to/zipfile/main.zip", null), new HashMap<>());
readAllLines("sample.txt");
在哪里
public List<String> readAllLines(String fileName) {
List<String> file = new ArrayList<>();
Path rootDir = fileSystem.getRootDirectories().iterator().next();
try (DirectoryStream<Path> files = Files.newDirectoryStream(rootDir,
entry -> entry.toString().equalsIgnoreCase("/" + fileName))) {
Path path = files.iterator().next();
file = Files.readAllLines(path, Charset.forName("ISO-8859-1"));
} catch (NoSuchElementException | IOException e) {
e.printStackTrace();
}
return file;
}
我想问一下,是否可以阅读这个“sample.txt”文件,它是否位于 2 个 zips 包中。像 mainzip.zip/sample.zip/sample.txt
mainzip.zip
|
|-sample.zip
|
|-sample.txt
|-another.zip
当然,我现在确实想解压缩 mainzip.zip。
感谢您的任何提示