• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Traversing a directory inside WAR

I deploy an application in an unexploded war. I know how to get an input stream from a resource if I know the file name inside the war. However, is there a way to read a directory from the resource to get the names of files in the directory?
For example, if I have a directory like "/WEB-INF/classes/x", I can get the URL for that, but I don't know how to get the file names inside directory x.
0
RogueCar
Asked:
RogueCar
  • 2
1 Solution
 
RogueCarAuthor Commented:
After some playing around, I came up with this:
          URL theFolderUrl = Z.context.getResource("/WEB-INF/classes/x");
          if (theFolderUrl == null) return;
          javax.naming.directory.DirContext jndd = (javax.naming.directory.DirContext)theFolderUrl.getContent();
          if (jndd == null) return;
          Enumeration e = jndd.list(""); // get all the files

This gives an enumeration of all the files in the directory.
0
 
RogueCarAuthor Commented:
Another note: the enumeration returns javax.naming.NameClassPair objects.  To get the file name, invoke the "getName()" method.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now