• java file 获取文件大小 返回 xx BT xx KB xx MB



       public static String GetFileSize(String Path){
        return GetFileSize(new File(Path));
       }
       
       
       public static String GetFileSize(File file){
        String size = ""; 
        if(file.exists() && file.isFile()){
        long fileS = file.length();
          DecimalFormat df = new DecimalFormat("#.00"); 
               if (fileS < 1024) {
                   size = df.format((double) fileS) + "BT";
               } else if (fileS < 1048576) {
                   size = df.format((double) fileS / 1024) + "KB";
               } else if (fileS < 1073741824) {
                   size = df.format((double) fileS / 1048576) + "MB";
               } else {
                   size = df.format((double) fileS / 1073741824) +"GB";
               }
        }else if(file.exists() && file.isDirectory()){
        size = "";
        }else{
        size = "0BT";
        }
        return size;
       }
  • 相关阅读:
    ugui点击穿透判断
    c#字符串代码,动态创建编译器
    github项目分享
    unity 2d 版的lookAt
    unity全屏截图
    shader例子
    AcWing 329. 围栏障碍训练场
    AcWing 326. XOR和路径
    AcWing 324. 贿赂FIPA
    AcWing 322. 消木块
  • 原文地址:https://www.cnblogs.com/xzcBY/p/7595259.html
Copyright © 2020-2023  润新知