Solved

Reading file names

Posted on 2004-09-01
3
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 25 total points
ID: 11956709
0
 
LVL 35

Expert Comment

by:girionis
ID: 11956731
0
 
LVL 18

Assisted Solution

by:bobbit31
bobbit31 earned 25 total points
ID: 11956756
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

751 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