zoukankan      html  css  js  c++  java
  • 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;
       }
  • 相关阅读:
    QuickContactBadge
    第一周——15选1
    UVA 10036 Divisibility
    POJ 3984 迷宫问题
    POJ 3258 River Hopscotch
    CodeForces 230A Dragons
    HDU 4450 Draw Something
    POJ 2485(PRIME算法)
    HDU 1213
    CodeForces 16E
  • 原文地址:https://www.cnblogs.com/xzcBY/p/7595259.html
Copyright © 2011-2022 走看看