我要开发一个功能,要求能够读取和写入windows文件对于用户和属组的完全控制,读取与执行,读取,写入,特殊权限等。
JAVA好像不能直接调用底层的文件权限。各位大侠提供一下解决思路,或有大神开发过,能给我点代码让我看看。
小人不胜感激,谢谢大家ntfs文件权限java

解决方案 »

  1.   

    用VC写,然后用java调vc写的exe ,这就是我的思路。
      

  2.   

    理由:windows的底层,还是由windows自家的东西做。
      

  3.   

    楼上说得很清楚了,用C写,用JNI调。
      

  4.   

    楼上说得很清楚了,用C写,用JNI调。
      

  5.   

    用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);
            
        }