日期:2014-05-20 浏览次数:20803 次
package test.io; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class AllFile { static File newFile = new File("F:" + File.separator + "test01.txt"); static int count = 1; public static void main(String[] args) { showAllFile(new File("C:"+File.separator)); } static void showAllFile(File file){ if(file.isFile()){ try { FileOutputStream fos = new FileOutputStream(newFile,true); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } count++; }else if (file.isDirectory()) { File list[] = file.listFiles(); if (list != null) { //使用递归获取每个文件夹 for (File ls : list) { showAllFile(ls); System.out.println(ls); System.out.println(count); } } } } }