如何使用JAVA操作ntfs文件权限

xjcuikai 2013-06-03 12:12:14
我要开发一个功能,要求能够读取和写入windows文件对于用户和属组的完全控制,读取与执行,读取,写入,特殊权限等。
JAVA好像不能直接调用底层的文件权限。各位大侠提供一下解决思路,或有大神开发过,能给我点代码让我看看。
小人不胜感激,谢谢大家
...全文
224 7 打赏 收藏 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yktd26 2013-06-03
  • 打赏
  • 举报
回复
用java 7是可以的不需要啥VC

public static void main(String... args) throws IOException{
        //Build file path
        Path file = new File("FilePath").toPath();
        
        //Read Acl
        AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);
        List<AclEntry> acl = view.getAcl();
        for(AclEntry ace: acl){
            System.out.printf("Ace Type: %s , Principal: %s\r\n", ace.type().name(), ace.principal().getName());
            String permsStr = "";
            for(AclEntryPermission perm : ace.permissions()){
                permsStr += perm.name()+" ";
            }
            System.out.printf("Ace Permissions: %s\r\n\r\n", permsStr.trim());
        }
        
        //Add Acl
        //Get user
        UserPrincipal user = file.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("Username");
        AclEntry entry = AclEntry.newBuilder()
         .setType(AclEntryType.ALLOW)
         .setPrincipal(user)
         .setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.READ_ATTRIBUTES)
         .build();
        acl.add(0, entry);   // insert before any DENY entries
        view.setAcl(acl);
        
    }
xjcuikai 2013-06-03
  • 打赏
  • 举报
回复
引用 3 楼 N27741 的回复:
理由:windows的底层,还是由windows自家的东西做。
大神,用C写,有没有例子啊?
forgetsam 2013-06-03
  • 打赏
  • 举报
回复
楼上说得很清楚了,用C写,用JNI调。
forgetsam 2013-06-03
  • 打赏
  • 举报
回复
楼上说得很清楚了,用C写,用JNI调。
n27741 2013-06-03
  • 打赏
  • 举报
回复
理由:windows的底层,还是由windows自家的东西做。
n27741 2013-06-03
  • 打赏
  • 举报
回复
用VC写,然后用java调vc写的exe ,这就是我的思路。
xjcuikai 2013-06-03
  • 打赏
  • 举报
回复
求大神给思路啊

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧