日期:2014-05-20 浏览次数:20673 次
import java.io.*; public class CreateFile { //private FileInputStream fis =null; //private FileOutputStream fos=null; static int n=1; // 1 private static File a=new File("D:"); //2 private File[] list; static int i; //3 /** * @param args */ public static void main(String[] args) { CreateFile cf=new CreateFile(); cf.find(a, n); System.out.println("总文件数是"+i+"个!"); } public void find(File a,int n){ if(!a.isDirectory()){ for(int i=1;i<n;i++){ System.out.print(" * "); } System.out.println(a.getAbsolutePath()); i++; } else{ list=a.listFiles(); if(list!=null){ for(File a1:list) find(a1,n+1); } } } }
public static void main(String[] args) { CreateFile cf=new CreateFile(); cf.find(cf.a, cf.n); //通过对象引用a,n. System.out.println("总文件数是"+cf.i+"个!"); //通过对象引用i. }
------解决方案--------------------