A: (1) Java does in some aspects than C + + do well, remember when I used C + + to traverse all the files under the folder, the long time of the time--and finally, the results of Baidu is different from the compilation environment provided. h header file is different, I'm going to go ... Cross-platform Good poor!
(2) Java inside the packaging of the class is very good, with it, to see the source code as long as the download of the corresponding SRC file awakened Association can see the detailed function of the internal implementation.
Two: Today's problem is to have a folder under all the data to be processed, the first step to get the name of all the files under this folder--java this function
The following method can also, I can get the name directly, do not need to first convert to file object file File=new file ("d:\\"); String test[]; Test=file.list (); for (int i=0;i<test.length;i++) { System.out.println (test[i]); }
Three: a complete project
Package Edu.tju.cs;import Java.io.file;import Java.util.arraylist;public class Calculate3dimensions {private static arraylist<string> subfilepaths = new arraylist<string> ();//subfolder collection private static arraylist<file> FileList = new arraylist<file> ();//The file collection under this directory public void Getallfiles (String filePath) {/* Above method is also possible, I can get the name directly, You do not need to convert to file object file File=new file ("d:\\"); String test[]; Test=file.list (); for (int i=0;i<test.length;i++) {System.out.println (test[i]); }*/file root = new File (FilePath); file[] files = root.listfiles (); for (File file:files) {if (File.isdirectory ()) {////Recursive call gets the file under subdirectories Getallfiles ( File.getabsolutepath ());//Add the path to the subfolder//subfilepaths.add (File.getabsolutepath ()); System.out.println ("Show" +filepath+ "all subdirectories and their files" +file.getabsolutepath ());} Else{//filelist.add (file);//Add File Full path Subfilepaths.add (File.getabsolutepath ()); System.out.println ("Show" +filepath+ "all subdirectories under" +file.getabsolutepath ());}}} public void R_dtxt (String filePath) {System.out.println ("display" + FilePath + "All sub-folders under:");//readtowrite rw = new Readtowrite (); for (String subfilepath:subfilepaths) {System.out.println System.out.println " File name: "+ Subfilepath);//rw.readtxtfile (Subfilepath);} SYSTEM.OUT.PRINTLN (all sub-Files under "show" + FilePath + ":&&&&&"); for (File file:filelist) { System.out.println ("File name:" + file);}} public static void Main (string[] args) {String FilePath = "D:\\tjdata_metro\\test"; Calculate3dimensions cal = new Calculate3dimensions (); Cal.getallfiles (FilePath); Cal. R_dtxt (FilePath);}}
The Traverse folder for Java file processing