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;
   }

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
猜你喜欢
  • 2022-12-23
  • 2021-08-16
  • 2021-04-12
  • 2021-09-28
  • 2022-12-23
  • 2021-04-17
  • 2022-12-23
相关资源
相似解决方案