How to access local files on a server in a JBoss application?

I am looking for access to all files in the local directory of a JBoss application. I can put the catalog anywhere in my war, including WEB-INF, if necessary. Then I want to access each file in the directory sequentially. In a regular application, if the directory was in the workplace, I could do something like:

File f = new File("myDir");
if(f.isDirectory && f.list().length != 0)
{
    for(String fileName : f.list())
    {
        //do Read-Only stuff with fileName
    }
}

I am looking for the best solution, so if I am going to do it wrong, please show me the correct path to access an unknown set of resources.

+2
source share
1 answer

, : , WAR, , , WAR .

ServletContext.getRealPath() . webapp :

String knownFilePath = servletContext.getRealPath("knownFile");
File webAppRootDir = new File(knownFilePath).getParentFile();

// and then as per the question
File f = webAppRootDir ;
if(f.isDirectory && f.list().length != 0)
{
    for(String fileName : f.list())
    {
        //do Read-Only stuff with fileName
    }
}

ServletContext .

+2

Source: https://habr.com/ru/post/1753893/


All Articles