AccessControlException:对可读文件的访问被拒绝

时间:2017-06-13 15:52:27

标签: java macos file exception permissions

我有这个文件:

➜ ✗ ll ltr /Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh

-rwxrwxrwx  1 eladb  eng   882B Jun 11 16:38 /Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh

我尝试从java中读取它:

        new FileInputStream(new File("/Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh"));

但是我收到了错误:

java.security.AccessControlException: access denied ("java.io.FilePermission" "/Users/eladb/WorkspaceQa/sdk-service/src/main/resources/convert_conditions.sh" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) ~[?:1.8.0_91]
    at java.security.AccessController.checkPermission(AccessController.java:884) ~[?:1.8.0_91]
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) ~[?:1.8.0_91]
    at java.lang.SecurityManager.checkRead(SecurityManager.java:888) ~[?:1.8.0_91]
    at java.io.FileInputStream.<init>(FileInputStream.java:127) ~[?:1.8.0_91]

为什么每个人都拥有该文件的读取权限?

1 个答案:

答案 0 :(得分:0)

操作系统的文件权限与它无关。查看堆栈跟踪,或实际上是异常的Javadoc。此异常来自Java安全管理器,而不是操作系统。您是在安全管理器下运行的(为什么?)并且您还没有授予自己访问.policy文件中该文件的权限。