Question

I have a web application in a servlet container.

How can I get the list of files inside security folder inside controller/servlet?

I tried something like this(which is not working):

File security_image_dir = new File("/beta/images/security/");
String security_images[] = security_image_dir.list();
Was it helpful?

Solution

The standard way of accessing files within a web environment is ServletContext.getResourceAsStream(String). If you want to get a list of files then you can try ServletContext.getResourcePaths()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top