我正在尝试将txt文件添加到zip文件中的文件夹中.
首先,我提取了zip文件的所有内容,然后添加了txt文件然后再压缩.
然后我读了一下nio方法,我可以修改zip而不提取它.使用这种方法,我可以将txt文件添加到zip的主文件夹,但我不能更深入.
testing.zip文件中有res文件夹.
这是我的代码:
Path txtFilePath = Paths.get("\\test\\prefs.txt");
Path zipFilePath = Paths.get("\\test\\testing.zip");
FileSystem fs;
try {
fs = FileSystems.newFileSystem(zipFilePath, null);
Path fileInsideZipPath = fs.getPath("res/prefs.txt"); //when I remover "res/" code works.
Files.copy(txtFilePath, fileInsideZipPath);
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
我得到以下异常:
java.nio.file.NoSuchFileException: res/