zoukankan      html  css  js  c++  java
  • 编写一个程序,指定一个文件夹,能自动计算出其总容量

    package filetest;
    import java.io.File;
    import java.io.IOException;
    
    public class FileEdit {
    double size=0.0;
    //计算文件或文件夹的大小,单位MB
    public double getSize(File file){
    //判断文件是否存在
    if(file.exists()) {
    if(!file.isFile()) {
    //获取文件大小
    File[] fl = file.listFiles();
    double ss=0;
    for(File f : fl)
    ss += getSize(f);
    return ss;
    }else {
    double ss = (double) file.length()/1024/1024;
    System.out.println(file.getName()+":"+ss+"MB");
    return ss;
    }
    }else {
    System.out.println("文件或文件夹不存在,请检查文件路径是否正确!");
    return 0.0;
    }
    }
    public static void main(String[] args) throws IOException{
    FileEdit fd = new FileEdit();
    double all = fd.getSize(new File("C:\Users\FuHeishi826\Desktop\壹青年"));
    System.out.println("All: "+all+"MB");
    }
    }
  • 相关阅读:
    Dynamics CRM9.0更新了Chrome后菜单按钮变形
    质量属性
    机器学习理解
    大道之简的理解
    架构之美理解
    1.13
    1.12
    1.11
    1.10
    Flex 替换输入的字符串
  • 原文地址:https://www.cnblogs.com/chenyuchun/p/9985859.html
Copyright © 2011-2022 走看看