public class test {
private int sum; //文件夹大小
private String path; //路径
private File f;
public static void main(String[]args) throws IOException
{
test t=new test("D:/d");
System.out.println(t.getSum());
}
public test(String path)
{
this.path=path;
this.f=new File(path);
N(this.f);
}
public int getSum()
{
return this.sum;
}
//递归打印获得文件夹大小
private int N(File f)
{
if(null!=f&&f.exists())
{
if(f.isFile()) //是文件才能获得大小
{
sum+=f.length();
}
else if(f.isDirectory())
{
File[] ss=f.listFiles();
for(File r:ss)
{
N(r);
}
}
}
return sum;
}
}
当前题目:java_io_面向对象风格递归获得文件夹大小
网页地址:https://www.cdcxhl.com/article40/jhdeho.html
成都网站建设公司_创新互联,为您提供服务器托管、响应式网站、营销型网站建设、静态网站、App设计、网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联