Learn how to a build a cloud-first strategyRegister Now


Getting the list of files in a directory

Posted on 2005-04-24
Medium Priority
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
  • 2
LVL 15

Expert Comment

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

Accepted Solution

aozarov earned 200 total points
ID: 13856358
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");

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 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