Arjun
Arjun

Reputation: 6729

Java: fetching the list of file names in a directory inside a war file

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();

Upvotes: 3

Views: 6046

Answers (1)

Suraj Chandran
Suraj Chandran

Reputation: 24791

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()

Upvotes: 5

Related Questions