3 import java.text.DecimalFormat;
\r
5 public class MemoryInfo {
\r
7 public static String getMemoryInfo() {
\r
8 DecimalFormat f1 = new DecimalFormat("#,###KB");
\r
9 DecimalFormat f2 = new DecimalFormat("##.#");
\r
10 long free = Runtime.getRuntime().freeMemory() / 1024;
\r
11 long total = Runtime.getRuntime().totalMemory() / 1024;
\r
12 long max = Runtime.getRuntime().maxMemory() / 1024;
\r
13 long used = total - free;
\r
14 double ratio = (used * 100 / (double)total);
\r
16 "Java Memory: total=" + f1.format(total) + "
\81A" +
\r
17 "used=" + f1.format(used) + " (" + f2.format(ratio) + "%)
\81A" +
\r
18 "available="+f1.format(max);
\r