zoukankan      html  css  js  c++  java
  • java 判断文件的大小

    public static String getNetFileSizeDescription(long size) {
            StringBuffer bytes = new StringBuffer();
            DecimalFormat format = new DecimalFormat("#####.0");
            if (size >= 1024 * 1024 * 1024) {
                double i = (size / (1024.0 * 1024.0 * 1024.0));
                bytes.append(format.format(i)).append("GB");
            }
            else if (size >= 1024 * 1024) {
                double i = (size / (1024.0 * 1024.0));
                bytes.append(format.format(i)).append("MB");
            }
            else if (size >= 1024) {
                double i = (size / (1024.0));
                bytes.append(format.format(i)).append("KB");
            }
            else if (size < 1024) {
                if (size <= 0) {
                    bytes.append("0B");
                }
                else {
                    bytes.append((int) size).append("B");
                }
            }
    
            return bytes.toString();
        }

    非本人原创

  • 相关阅读:
    linux 进程操作脚本
    go 项目监听重启
    go 小题
    beego 基础
    beego 接口开发
    beego 安装
    mongo curd
    html的学习(一)
    ssl
    java编码的学习
  • 原文地址:https://www.cnblogs.com/wcnwcn/p/11805125.html
Copyright © 2011-2022 走看看