如何获得文件大小以KB和MB android中 [英] How to get file size in KB and MB in android
本文介绍了如何获得文件大小以KB和MB android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想code,我能得到的文件大小,并更改为KB和MB
I want code that i can get file size and change it to KB and MB
562 KB = 562 KB
1024 KB = 1 MB
2152 KB = 2.15 MB
感谢您提前。
推荐答案
下面是:
public String size(int size){
String hrSize = "";
double m = size/1024.0;
DecimalFormat dec = new DecimalFormat("0.00");
if (m > 1) {
hrSize = dec.format(m).concat(" MB");
} else {
hrSize = dec.format(size).concat(" KB");
}
return hrSize;
}
这篇关于如何获得文件大小以KB和MB android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文