java.security.AccessControlException: File accessible thru browser but not within same server

ε祈祈猫儿з 提交于 2020-01-11 07:17:22

问题


So to not repeat myself too much, please refer to serve static image along side java google-enpoint api.

As you can see from the referenced link, I am able to view the image through the url. However, when I am trying to read filenames using similar code to

public void listFilesForFolder(final File folder) {
    for (final File fileEntry : folder.listFiles()) {
        if (fileEntry.isDirectory()) {
            listFilesForFolder(fileEntry);
        } else {
            System.out.println(fileEntry.getName());
        }
    }
}

final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);

I get a security exception

java.security.AccessControlException: access denied ("java.io.FilePermission" "/myImages" "read")

Does anyone know the fix? How come the call thru the browser show the image and yet a call from within the server itself throws an exception? I find that strange.


回答1:


If you've configured a file as a "static" resource, it'll be served up by a separate pool of servers that are optimized for serving static content. A consequence is that the file isn't available to be opened from your app. "resource" files are available for the app to open and read.

That's documented here.

You'll need to use a relative path when opening a resource. You've shown an absolute path above.




回答2:


If the server is running as a service, make sure that service has permissions to the folder and files you're trying to read.



来源:https://stackoverflow.com/questions/16513260/java-security-accesscontrolexception-file-accessible-thru-browser-but-not-withi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!