我跟着什麼this page告訴我,但我不能讓它工作。我需要它,以便在我的test.zip中有一個名爲「new」的文件夾。每當我運行下面的代碼時,它會給出一個FileAlreadyExistsException
,並只創建一個空的zip文件。Java:如何使用java.nio.file.FileSystem創建一個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庫文件系統而不是一般文件系統 –