1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public class Test {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null,
String.join("\n",
String.format("Paramètres : %s", Arrays.toString(args)),
String.format("%s %s",format(Runtime.getRuntime().freeMemory()), "libre"),
String.format("%s %s",format(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()), "occupé"),
String.format("%s %s",format(Runtime.getRuntime().totalMemory()), "réservé"),
String.format("%s %s",format(Runtime.getRuntime().maxMemory()), "maximum"))
);
}
private static String format(long size) {
int u = 0;
for (;size > 1024*1024; size>>= 10) {
u++;
}
if (size > 1024)
u++;
return new DecimalFormat("#.#"+String.format("%s%c%sB", u==0?"":" ", " KMGTPE".charAt(u), u==0?"":"i")).format(size/1024f);
}
} |
Partager