Get Memory Size Strings
import java.text.DecimalFormat;
class Main{
/**
*
* @return
*/
public static String getMemorySizeStrings() {
DecimalFormat dformat = new DecimalFormat("###,###,###,##0");
String mem = null;
long freeSize = 0L;
long totalSize = 0L;
long usedSize = 0L;
try {
Runtime info = Runtime.getRuntime();
freeSize = info.freeMemory();
totalSize = info.totalMemory();
usedSize = totalSize - freeSize;
mem = "free=" + dformat.format(freeSize) + " byte / " + "total="
+ dformat.format(totalSize) + " byte / " + "used="
+ dformat.format(usedSize) + " byte";
} catch (Exception e) {
e.printStackTrace();
}
return mem;
}
}
Related examples in the same category