java file 获取文件大小 返回 xx BT xx KB xx MB
2017-09-26 10:05
260 查看
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;
}
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;
}
相关文章推荐
- Android 获取文件大小转换MB.GB.KB.B
- PHP获取远程文件大小 如果加判断文件大小以KB MB GB
- 后台获取文件大小 自动转换 B KB MB GB
- 获取app文件大小 并对应响应单位:B KB MB GB; DecimalFormat
- Android 技术总结(014)—— 获取与转转文件的大小(B,KB,MB,GB)
- java 根据图片地址获取到图片的大小,单位kb或者Mb
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位
- 取文件的大小 (KB,MB,GB...)
- 取文件的大小 (KB,MB,GB...)
- 文件大小long转KB,MB,GB
- java 获取网络servelt 返回下载文件大小
- php文件大小单位转换GB MB KB
- 文件大小单位实现,B,KB,MB,GB,TB.....
- 我的Android进阶之旅------>Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换)
- C#转换文件大小格式(GB/MB/KB/B)
- PHP获取文件大小并转化为KB、MB、GB单位
- python 文件大小显示kb、mb或gb等
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位
- [已解决]批处理查看文件大小的字节怎样转换成KB和MB?