View Single Post
  #2 (permalink)  
Old 04-21-2008, 12:18 PM
DonCash's Avatar
DonCash DonCash is offline
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 240
DonCash will become famous soon enoughDonCash will become famous soon enough
Hey moomoo,

Welcome to the Java-Forums!

You can use this code to list all files in a directory:

Code:
String path = "."; String files; File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); System.out.println(files); } }
Add your code into the for loop.

If you want to list .txt files only then use this code:

Code:
String path = "."; String files; File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); if (files.endsWith(".txt") || files.endsWith(".TXT")){ System.out.println(files); } } }
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote