Traverse directory structure

Hi does anyone know how I would traverse a directory structure?Problem:I need to search through a selected directory of txt files searching for a certain string. I also need to be able to search each and every sub directory and so on.
[262 byte] By [ljcaseya] at [2007-10-1 7:29:27]
# 1

yes.

Use java.io.File to traverse files. You could do this depth-first or breadth-first using recursion or use an iterative approach.

For each file you visit, open a BufferedReader and read line by line using String.indexOf(searchString). This assumes the certain string cannot span lines.

Good luck

IanSchneidera at 2007-7-9 18:49:57 > top of Java-index,Java Essentials,Java Programming...
# 2
I can handle the recursion and the depth/breadth first stuff but the bit im stuck on is how to tell whether something is a directory or a file. (if you get what i mean) and if its a directory how to enter that directory. Thats the only part I am puzzled on.
ljcaseya at 2007-7-9 18:49:58 > top of Java-index,Java Essentials,Java Programming...
# 3
I thought that java.io.File had an isDirectory() method. Did you miss that one in your scan of the API documentation?
DrClapa at 2007-7-9 18:49:58 > top of Java-index,Java Essentials,Java Programming...