Source Code : Format file length in string
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Format file length in string
public class Utils {
public static final String format(long l) {
String s = String.valueOf(l);
int digits = 0;
while (s.length() > 3) {
s = s.substring(0, s.length() - 3);
digits++;
}
StringBuffer buffer = new StringBuffer();
buffer.append(s);
if ((s.length() == 1) && (String.valueOf(l).length() >= 3)) {
buffer.append(".");
buffer.append(String.valueOf(l).substring(1, 3));
} else if ((s.length() == 2) && (String.valueOf(l).length() >= 3)) {
buffer.append(".");
buffer.append(String.valueOf(l).substring(2, 3));
}
if (digits == 0) {
buffer.append(" B");
} else if (digits == 1) {
buffer.append(" KB");
} else if (digits == 2) {
buffer.append(" MB");
} else if (digits == 3) {
buffer.append(" GB");
} else if (digits == 4) {
buffer.append(" TB");
}
return buffer.toString();
}
}
Thank with us