你可以从Runtime类中获取一些有限的内存信息。确实不是你要找的东西,但我想为完整起见会提供它。这是一个小例子。编辑:你还可以从
java.io.File类获取磁盘使用情况信息。磁盘空间使用情况需要Java 1.6或更高版本。
public class Main { public static void main(String[] args) { System.out.println("Available processors (cores): " + Runtime.getRuntime().availableProcessors()); System.out.println("Free memory (bytes): " + Runtime.getRuntime().freeMemory()); long maxMemory = Runtime.getRuntime().maxMemory(); System.out.println("Maximum memory (bytes): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory)); System.out.println("Total memory available to JVM (bytes): " + Runtime.getRuntime().totalMemory()); File[] roots = File.listRoots(); for (File root : roots) { System.out.println("File system root: " + root.getAbsolutePath()); System.out.println("Total space (bytes): " + root.getTotalSpace()); System.out.println("Free space (bytes): " + root.getFreeSpace()); System.out.println("Usable space (bytes): " + root.getUsableSpace()); } }}


