标签:io java ar for 文件 sp on c ad
public static void main(String[] args){ String filePath = "文件夹路径"; try { System.out.println("开始读取文件夹"); List<String> list = new ArrayList<String>(); List<String> files = readFile(list,filePath); Iterator<String> it = files.iterator(); while(it.hasNext()){ System.out.println(">>>"+it.next()); } System.out.println("文件夹读取结束"); } catch (Exception e) { e.printStackTrace(); System.out.println("系统出错了"); // TODO Auto-generated catch block e.printStackTrace(); } } //读文件夹文件 public static List<String> readFile(List<String> list,String path)throws Exception{ File file = new File(path); if(!file.isDirectory()){ list.add(file.getPath()); }else if(file.isDirectory()){ String[] files = file.list(); for(int i=0;i<files.length;i++){ readFile(list, path+"\\"+files[i]); } } return list; }
标签:io java ar for 文件 sp on c ad
原文地址:http://my.oschina.net/pumpkin0523/blog/313779