java读取文件大小

2015-06-03 0 255
java读取文件大小
public static void main(String[] args) {
        String src = "c://test.apk";
        File file = new File(src);
        DecimalFormat df = new DecimalFormat("0.00");
        String fileSizeString = "";
         if (file.length() < 1024) {
            fileSizeString = df.format((double) file.length()) + "B";
        } else if (file.length() < 1048576) {
            fileSizeString = df.format((double) file.length() / 1024) + "K";
        } else if (file.length() < 1073741824) {
            fileSizeString = df.format((double) file.length() / 1048576) + "M";
        } else {
            fileSizeString = df.format((double) file.length() / 1073741824) + "G";
        }
         System.out.println("==========>"+fileSizeString);
    }

遇见资源网 java java读取文件大小 http://www.ox520.com/9404.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务