java非递归检索文件夹下所有文件
DateFormat df = DateFormat.getDateTimeInstance(); LinkedList<File> folders = new LinkedList<File>(); LinkedList<File> filelists = new LinkedList<File>(); File dir = new File("E:\\wangk\\wd"); File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()){//如果文件夹放入LinkedList if(!StringUtils.equalsIgnoreCase(".svn",files[i].getName())) folders.add(files[i]); }else{ filelists.add(files[i]); } } //如果没有字文件夹 while (!folders.isEmpty()) { //获得第一个文件 File file = (File) folders.removeFirst(); if (file.isDirectory()) { //如果文件夹 files = file.listFiles(); if (files == null) continue; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()){ if(!StringUtils.equalsIgnoreCase(".svn",files[i].getName())) folders.add(files[i]); } else { filelists.add(files[i]); //Date date = new Date(); //date.setTime(files[i].lastModified()); //String filepath = files[i].getAbsolutePath(); //System.out.println(filepath+"("+df.format(date)+")"); } } } else { filelists.add(file); //System.out.println(file.getAbsolutePath()); } } System.out.println(filelists.size());