WEB开发网
开发学院WEB开发Jsp JAVA列出某文件夹下的所有文件 阅读

JAVA列出某文件夹下的所有文件

 2009-11-09 21:01:18 来源:WEB开发网   
核心提示:view plaincopy to clipboardPRint?import java.io.*; public class ListFiles { private static String s = ""; private static BufferedReader in = new Buffe
view plaincopy to clipboardPRint?
import java.io.*;  
 
public class ListFiles {  
 
  private static String s = "";  
  private static BufferedReader in = new BufferedReader(  
      new InputStreamReader(System.in));  
 
  public static void main(String[] args) {  
 
    try {  
      s = in.readLine();  
      getFileList(s);  
      in.close();  
 
    } catch (IOException e) {  
      e.printStackTrace();  
    }  
  }  
 
  public static void getFileList(String directory) {  
 
    File f = new File(directory);  
    File[] files = f.listFiles();  
    for (int i = 0; i < files.length; i++) {  
      if (files[i].isFile()) {  
        System.out.println("文件:" + files[i]);  
      } else {  
        System.out.println("目录:" + files[i]);  
        // System.out.println("目录绝对地址:" + files[i].getAbsolutePath());  
        getFileList(files[i].getAbsolutePath());  
 
      }  
    }  
  }  
} 

Tags:JAVA 列出 文件夹

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接