您的位置:首页 > 其它

文件流---获取文件的大小(图片、视频、文件......)

2017-08-28 11:27 260 查看
//获取文件大小

    public static String GetFileSize(String Path) {

        File file = new File(Path);

        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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: