文件流---获取文件的大小(图片、视频、文件......)
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;
}
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;
}
相关文章推荐
- PB获取图片文件原始大小的API函数
- Unity——网页获取视频文件播放,获取图片更换纹理
- 用JAVA获取视频文件中的帧图片并等比缩放
- 文件流---获取图片的宽、高、大小
- 获取图片和文件的大小和格式
- 获取系统的图片,音频和视频文件
- 用javaScript获取文件,jpg图片大小
- Android获取文件类型是图片还是视频
- Matlab 处理avi视频文件为单帧任意大小图片
- [Cocoa]_[初级]_[获取图片文件的属性值:如图片大小、位深度、宽高、最后修改日期]
- Android获取本机各种类型文件列表(音乐、视频、图片、文档等)
- jave 获取音视频文件的大小、以及播放时长
- Android获取SD卡上图片和视频文件及其缩略图
- 获取图片宽度、高度、格式、文件大小的信息
- java获得U盘根目录、读取图片视频头文件信息、获取视频时长
- JS获取图片/图像文件大小的代码
- Android之图片压缩和Uri与String类型的路径转换,获取图片,文件大小的工具类
- java获得U盘根目录、读取图片视频头文件信息、获取视频时长
- Android开发之多媒体文件获取工具类实例【音频,视频,图片等】
- 用javaScript获取文件,jpg图片大小