Java向zip压缩包中添加文件
Java向zip压缩包中添加文件
Java7的Zip File System 可以向压缩文件中添加文件,也可以修改压缩文件中的文件,并且不需要手动重新打包。
下面示例为向压缩文件中写入文件
Map<String, String> env = new HashMap<>();
env.put("create", "true");
Path path = Paths.get("test.zip");
URI uri = URI.create("jar:" + path.toUri());
try (FileSystem fs = FileSystems.newFileSystem(uri, env))
{
Path nf = fs.getPath("new.txt");
try (Writer writer = Files.newBufferedWriter(nf, StandardCharsets.UTF_8, StandardOpenOption.CREATE)) {
writer.write("hello");
}
}
Loading...