java遍历所有目录和文件
package xian;
?
import java.io.File;
import java.util.ArrayList;
?
public class GetFile {
private static ArrayList<String> fileList = new ArrayList<String>();
? ?public static void main(String[] args) {
String filePath="E://小仙U盤";
getFiles(filePath);
}
? ? /**
? ? ?* 通過遞歸過得目錄和文件
? ? ?*/
? ?public static void getFiles(String filePath){
? File fileAll=new File(filePath);
? File[] files=fileAll.listFiles();
? for(File file:files){
? if(file.isDirectory()){//如果是目錄
? //遞歸
? getFiles(file.getAbsolutePath());
? fileList.add(file.getAbsolutePath());
? System.out.println("顯示"+filePath+"下所有子目錄及其文件"+file.getAbsolutePath());
? }else{
? System.out.println("顯示"+filePath+"下所有子目錄"+file.getAbsolutePath());
? }
? }
? ?}
}
顯示E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目錄E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-focus-bg.gif
顯示E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目錄E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-focus-corners.gif
顯示E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目錄E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-focus-sides.gif
顯示E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目錄E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-over-bg.gif
顯示E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn下所有子目錄E:\小仙U盤\extjs\ExtJs包和Api\ext-4.0.7-gpl\resources\themes\p_w_picpaths\gray\btn\btn-default-toolbar-small-over-corners.gif
?
?
轉載于:https://www.cnblogs.com/hackerxian/p/10871684.html
總結
以上是生活随笔為你收集整理的java遍历所有目录和文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 沈南鹏:从五大物理定律看新商业法则
- 下一篇: 【CSON原创】 图片放大器效果发布