java.lang.UnsupportedOperationException: 'posix:permissions' 在 Windows 上不支持作为初始属性
2022-09-02 21:13:40
我正在使用Java 7 File API。我写了一个类,在Ubuntu上工作正常,创建目录,但是当我在Windows上运行相同的代码时,它会抛出错误:
Exception in thread "main" java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute
at sun.nio.fs.WindowsSecurityDescriptor.fromAttribute(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.createDirectory(Unknown Source)
at java.nio.file.Files.createDirectory(Unknown Source)
at java.nio.file.Files.createAndCheckIsDirectory(Unknown Source)
at java.nio.file.Files.createDirectories(Unknown Source)
at com.cloudspoke.folder_permission.Folder.createFolder(Folder.java:27)
at com.cloudspoke.folder_permission.Main.main(Main.java:139)
我的文件夹类代码是
package com.cloudspoke.folder_permission;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.UserPrincipal;
import java.util.Set;
public class Folder{
// attributes required for creating a Folder
private UserPrincipal owner;
private Path folder_name;
private FileAttribute<Set<PosixFilePermission>> attr;
public Folder(UserPrincipal owner,Path folder_name,FileAttribute<Set<PosixFilePermission>> attr){
this.owner=owner;
this.folder_name=folder_name;
this.attr=attr;
}
//invoking this method will create folders
public void createFolder(){
try {
//createDirectories function is used for overwriting existing folder instead of createDirectory() method
Files.createDirectories(folder_name, attr);
Files.setOwner(folder_name, owner);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("created Folder "+this.folder_name);
}
}
错误来自 的方法。createFolder
Folder
如何解决此错误?