手上的这个项目要做一个浏览服务器的功能。用到了这个方法。
Code 1 import java.io.File; 2 import java.util.ArrayList; 3 public class FileSystem1 { 4 private static ArrayList filelist = new ArrayList(); 5 6 public static void main(String[] args) { 7 8 long a = System.currentTimeMillis(); 9 refreshFileList( " D:\\Tomcat\\webapps\\HaodeWeb\\publish\\Image " ); 10 System.out.println(System.currentTimeMillis() - a); 11 } 12 public static void refreshFileList(String strPath) { 13 File dir = new File(strPath); 14 File[] files = dir.listFiles(); 15 16 if (files == null ) 17 return ; 18 for ( int i = 0 ; i < files.length; i ++ ) { 19 if (files[i].isDirectory()) { 20 refreshFileList(files[i].getAbsolutePath()); 21 } else { 22 String strFileName = files[i].getAbsolutePath().toLowerCase(); 23 System.out.println( " --- " + strFileName); 24 filelist.add(files[i].getAbsolutePath()); 25 } 26 } 27 } 28 } 29