import java.io.File;
import java.io.FileFilter;
import org.junit.Test;
public class TestFile
{
public static long size;
public static void main(String[] args)
{
TestFile t = new TestFile();
String path = "C:/3000soft";
t.countSize(path);
System.out.println("文件夹大小为:" + size / 1024.0 / 1024.0 + "M");
}
public void countSize(String pathname)
{
File f = new File(pathname);
if (!f.exists())
{
return;
}
if (f.isFile())
{
size += f.length();
System.out.println(f.getAbsolutePath());
return;
}
File[] child = f.listFiles();
for (int i = 0; i < child.length; i++)
{
countSize(child[i].getAbsolutePath());
}
}
}
转载于:https://my.oschina.net/u/1243742/blog/774991