在Java 7中,我们获得了Zip文件系统,该文件系统允许以zip(jar,war)格式添加和更改文件,而无需手动重新打包。
我们可以直接将文件写入zip文件中,如下例所示。
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"); }}


