To get a listing of all files in the current directory see this thread, actually its short enough that I might as well post the code again.
Now, rather than printing out the filename, you can use the string function (stringname).endsWith(".txt") to see if it has the .txt extention. That will give you all .txt files in the current directory. To do sub directories, you will need to loop through and (recursively) check each subsequent directory for txt files as well as more directorys. If you need help with recusrion, check out a google search here. If you need more help, just post.
- Donny Nadolny<br />The pen is mightier than the sword, and considerably easier to write with.
Thanks Jeff Langr. System.getProperties().getProperty("user.dir"); -> it starts from the current working directory. If i want to give any directory path (like D:/hai/bye ), then how can i dynamically mention my directory path ?