Java version of folder Traversal
The File class in Java (the File class, in fact, feels that the File class is a little misleading, it would be better to use the "File path") has a list method, and will return all the files and directories in the specified path, this method and simple recursion can be used to write a simple file traversal program.
import java.io.File;import java.io.FileWriter;import java.io.IOException;public class test_for_team_study_2{public static void traverse(String name, FileWriter wt) throws IOException{wt.write(name + "\r\n");File path = new File(name);String[] list = path.list();if( null == list )return ;for(int i = 0; i < list.length; i ++)if( -1 == list[i].indexOf(".") )traverse(name + "/" + list[i], wt);}public static void main(String[] args) throws IOException{FileWriter wt = new FileWriter("C:/Users/Administrator/Desktop/file in D.out");String name = "D:/";File path = new File(name);String[] list = path.list();for(int i = 0; i < list.length; i ++){wt.write("now is the file#:" + i + "\r\n==========================\r\n");traverse(name + "/" + list[i], wt);wt.write("\r\n\r\n\r\n");}wt.flush();wt.close();System.out.println("finished!");}}