我想问是否可以访问和修改压缩在另一个 zip 包中的 zip 文件内的文本文件。
我知道我可以像这样使用 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");
Run Code Online (Sandbox Code Playgroud)
在哪里
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;
}
Run Code Online (Sandbox Code Playgroud)
我想问一下,如果这个“sample.txt”文件位于 2 个 zip 包中,是否也可以读取它。像 mainzip.zip/sample.zip/sample.txt
mainzip.zip
|
|-sample.zip
|
|-sample.txt
|-another.zip
Run Code Online (Sandbox Code Playgroud)
当然,我现在想要解压 mainzip.zip。
感谢您的任何提示
我有示例类:
class Example {
private:
int testValue1;
int testValue2;
int testValue3;
public:
Example(int pVal1, int pVal2, int pVal3);
Example(const Example);
const Example operator =(const Example);
inline int getValue1() { return testValue1; }
inline int getValue2() { return testValue2; }
inline int getValue3() { return testValue3; }
};
Run Code Online (Sandbox Code Playgroud)
在源代码中,我有示例对象的std :: vector.
是否有可能使用某些std :: algorithm,std :: numeric函数将向量中所有Obejcts的Value1求和
像这样的东西:std :: accumulate(vector.begin(),vector.end(),0,SomeFunctorOrOthers)....
当然我可以使用迭代器......但如果有可能,我想知道它
非常感谢你!