现在的位置: 首页 > 综合 > 正文

xxx

2013年05月05日 ⁄ 综合 ⁄ 共 1044字 ⁄ 字号 评论关闭

import java.io.File;

import java.util.ArrayList;

 

 

public class ScanFile {

private static int FolderCount = 0;

private static int FileCount = 0;

private static ArrayList<File> fileList = new ArrayList<File>();

private static ArrayList<File> fileList2 = new ArrayList<File>();

public static void main(String[] args)

{

File file = new File("D://test2");

fileList2.add(file);

File file2 = new File("D://test");

fileList2.add(file2);

File file3 = new File("D://README");

fileList2.add(file3);

File file4 = new File(".project");

fileList2.add(file4);

while(!fileList2.isEmpty())

{

File temp = fileList2.get(0);

System.out.println("xxxxxxtemp.path = " + temp.getPath());

if(null != temp)

{

fileList = getFile(temp);

}

fileList2.remove(0);

}

System.out.println("FolderCount = " + FolderCount + "  FileCount++ = " + FileCount);

 

}

private static ArrayList<File> getFile(File f){

File[] ff = f.listFiles();

if(null == ff && f.isFile())

{

FileCount++;

return fileList;

}

for (File child : ff) {

if(child.isDirectory())

{

FolderCount++;

getFile(child);

System.out.println(child.getPath());

}

else

{

FileCount++;

fileList.add(child);

System.out.println(child.getPath());

}

}

return fileList;

}

}

抱歉!评论已关闭.