I want to ask if is possible to access and modify a text file inside a zip file which is zipped in another zip package.
I know that can I access the file using Java.nio FileSysten like this. In this example to read all the lines in "sample.txt" file.
FileSystem fileSystem = FileSystems.newFileSystem(new URI("jar:file", "sample/path/to/zipfile/main.zip", null), new HashMap<>());
readAllLines("sample.txt");
where
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;
}
I want to ask, if is possible to read this "sample.txt" file also if it will be located in 2 zips packages in depth. Like mainzip.zip/sample.zip/sample.txt
mainzip.zip
|
|-sample.zip
|
|-sample.txt
|-another.zip
of course I do now want to unzip the mainzip.zip.
Thanks for any tips