Getting the list of files in a directory

Posted on 2005-04-24
Last Modified: 2010-03-31
hi Experts
              I am being faced by this follwoing scenario.. I have to get the list of all *.xml file that are present in a particular directory into a String Array. The constraint is that    i will not no before hand how many files are there
How do i accomplish this..

Thanx in advance

Question by:noviceWebProgrammer
    LVL 15

    Expert Comment

    File file = new File(<the_directory_path>);
    String[] fileNamesInthatDirectory = file.list();
    LVL 15

    Accepted Solution

    You can also provide a filter to list only xml files:
    file.list(new FilenameFilter()
    public boolean accept(File dir,
                          String name)
    return name.endsWith(".xml");

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    EvenOdd challenge 10 67
    java JDK Download 7 49
    stringclean challenge 26 43
    Starting to learn JAVA, 7 34
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now