Traversing a directory inside WAR

Posted on 2009-12-16
Last Modified: 2013-11-24
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.
Question by:RogueCar

    Accepted Solution

    After some playing around, I came up with this:
              URL theFolderUrl = Z.context.getResource("/WEB-INF/classes/x");
              if (theFolderUrl == null) return;
     jndd = (;
              if (jndd == null) return;
              Enumeration e = jndd.list(""); // get all the files

    This gives an enumeration of all the files in the directory.

    Author Comment

    Another note: the enumeration returns javax.naming.NameClassPair objects.  To get the file name, invoke the "getName()" method.

    Featured Post

    How does your email signature look on mobiles?

    Do your employees use mobile devices to reply to emails? With mobile becoming increasingly important to the business world, it is in your best interest to make sure that your email signature looks great across all types of devices.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    constructor while deserilizing object 16 46
    copyEndy  challenge 15 40
    mapBully challenge 6 53
    What is JNDI datasource in spring 1 19
    Problem: Windows 32bit running out of paging space. Solution: Add additional page files on separate partitions. Background: By default Windows creates only one page file on the partition you install Windows on. You may know that the maximu…
    Hello, As I have seen there a lot of requests regarding monitoring and reporting for exchange 2007 / 2010 / 2013 I have decided to post some thoughts together and link to articles that have helped me. Of course a lot of information you can get…
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now