【发布时间】:2015-04-16 12:46:35
【问题描述】:
我已按照this page 告诉我的内容进行操作,但我无法让它工作。我想要它,以便在我的 test.zip 中有一个名为“new”的文件夹。每当我运行下面的代码时,它都会给出FileAlreadyExistsException,并且只会创建一个空的 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/");
Files.createDirectory(path);
} catch (IOException e) {
e.printStackTrace();
}
【问题讨论】:
-
修复了标题拼写,删除了文件系统标签,因为这是 Java 库文件系统而不是通用文件系统