0
我有位代碼,是應該在系統上的臨時文件的位置創建一個臨時目錄:NIO Files.createTempDirectory在Windows上引起異常
try {
Path tempdir = Files.createTempDirectory("tempmm");
tempdir.toFile().deleteOnExit();
tempFilename = format("%s/%s.zip", tempdir, meetId);
// Handle windows
//tempFilename = tempFilename.replace("\\", "/");
uri = URI.create("jar:file:" + tempFilename);
System.out.println("temp file uri = " + uri.toString());
} catch (IOException e) {
log.severe(format("Unable to create temporary directory: %s", e.toString()));
}
和
try (FileSystem zipfs = FileSystems.newFileSystem(uri, new HashMap<String, String>() {{ put("create", "true"); }})) {
Path externalMMFile = Paths.get(filePath);
Path pathInZipfile = zipfs.getPath(externalMMFile.getFileName().toString());
// copy Meet Manager Database file into the zip file
Files.copy(externalMMFile,pathInZipfile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.severe("Unable to create zip upload file!");
System.out.println(e.toString());
return false;
}
這是發生的異常:
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Ill
egal character in opaque part at index 11: jar:file:C:\DOCUME~1\David\LOCALS~1\T
emp\tempmm6286934818003944424/107.zip
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Ill
egal character in opaque part at index 11: jar:file:C:\DOCUME~1\David\LOCALS~1\T
emp\tempmm6286934818003944424/107.zip
有沒有人有任何想法我可以這樣做在AP獨立於平臺的方式?