Solved

Reading file names

Posted on 2004-09-01
3
247 Views
Last Modified: 2010-03-31
Hi,

How can I read the names of many files under one directory? I have about 30 *.doc files in a directory and would like to read the names of the files into my program.

Any tips/hints/code snippets would be greatly appreciated.
0
Comment
Question by:Programmer_to_be
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 25 total points
Comment Utility
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
0
 
LVL 18

Assisted Solution

by:bobbit31
bobbit31 earned 25 total points
Comment Utility
File f = new File("<path to dir>");

if (f.exists() && f.isDirectory()) {
   File[] files = file.listFiles();
   for (int i=0; i<files.length; i++)
   {
      System.out.println(files[i].getName());
   }
}
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 38
factorial example challenge 10 60
DO we need Java installed on a Windows PC and WHY ? 13 77
mockito example issue 8 26
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

762 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

8 Experts available now in Live!

Get 1:1 Help Now