这个问题提出了一个类似的问题。但是,在我的情况下,该目录在调用Files.createDirectories()
. 这发生在 Oracle JDK 10.0.2 上。
这是我的代码...
Set<PosixFilePermission> perms;
FileAttribute<?> attr;
Path path;
File directory;
directory = new File("/test/http/localhost_4452/UCF2b/Live");
path = directory.toPath();
perms = EnumSet.noneOf(PosixFilePermission.class);
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
attr = PosixFilePermissions.asFileAttribute(perms);
try
{
if (!directory.exists())
Files.createDirectories(path, attr);
}
catch (IOException e)
{
if (!directory.exists())
{
... collect more information about the state of the directory and its parent path ...
... add this information as a suppressed exception ...
throw e;
}
// else do nothing and assume another thread created the directory
}
这里是例外...
java.nio.file.FileAlreadyExistsException: /test/http/localhost_4452/UCF2b/Live
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:94)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:385)
at java.base/java.nio.file.Files.createDirectory(Files.java:682)
at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:789)
at java.base/java.nio.file.Files.createDirectories(Files.java:735)
at ...my code...
当前用户是root。这是收集到的有关目录及其父目录的诊断信息。catch如果目录不存在,则在块中收集此信息。
侃侃无极
红颜莎娜
相关分类