I developing spring application and I set mapping resources:

<resources mapping="/src/**" location="/src/" order="-1" />

Now I have access for all files inside src folder without loging and that is ok. Now I try to read all files inside src folder with File Class but now I do not have permission to read files. How to solve this?

File file = new File(rquest.getContextPath()+"/src");
file.setReadable(true, true);
System.out.println(file.listFiles());

So listFiles() function return null, I think that is problem with permission?

有帮助吗?

解决方案

This is not a permission problem. Your trying to access a file via r(e)quest.getContextPath() which is used for web access (not file system!)

If you want to access files in your workspace/deploy location of your project via the file-system, you should use on of the following methods:

Resource myData = new ClasspathResource("myData.xml"): - this will be relative to WEB-INF deploy directory

or:

new File(servletRequest.getSession().getServletContext().getRealPath("/")+"/your-path-relative-to-WEB-INF-deploy-path");

I personally recommend method #1

EDIT
Your questions suggests that you think your src folder is being deployed (copied to the server with your WAR/EAR/Built project, this is usually not true. Normally, the Webpages folder (whatever name you call it within your app) and everything inside of WEB-INF is being deployed. hoping this was helpful.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top