package com.file.test;
import java.io.File;
public class CountFileTest {
private String path;
private File file;
private long size;
private int fileCount;
private int dirCount = -1;
public CountFileTest(String path) {
super();
this.path = path;
this.file = new File(path);
count(file);
}
public long getSize() {
return size;
}
public int getFileCount() {
return fileCount;
}
public int getDirCount() {
return dirCount;
}
private void count(File file) {
if (file != null && file.exists()) {
if (file.isFile()) {
size += file.length();
this.fileCount++;
} else {
this.dirCount++;
for (File files : file.listFiles()) {
count(files);
}
}
}
}
}