import java.io.File;
public class test01 {
public static void main(String[] args) {
try {
String path = "C:\\tools\\Java\\workspace\\test001";//System.getProperty("user.dir");
(new test01()).showFileList(path);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void showFileList(String path) throws Exception {
File dir = new File(path);
File[] files = dir.listFiles();
int fileCnt = 0;
int dirCnt = 0;
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.isFile()) {
fileCnt++;// 파일 개수
//System.out.println("[File]" + file.getCanonicalPath().toString());
//System.out.println("[Directory CNT]" + file.getCanonicalPath().toString()+" " +fileCnt);
} else if (file.isDirectory()) {
dirCnt++;
//System.out.println("[Directory]" + file.getCanonicalPath().toString());
try {
showFileList(file.getCanonicalPath().toString());
} catch (Exception e) {
}
}
}
System.out.println(dir.getCanonicalPath().toString()+" file :"+fileCnt+" dirCnt:"+dirCnt);
}
}
단순하게 살기
Best Item들을 소소하게 적어보는 작은 공간입니다. by 야매코더