![](/img/trans.png)
[英]Is it feasible to get available system memory, disk space, cpu usage of a remote system only providing host name, Login UserId and Password
[英]how to find available system memory, disk space, cpu usage using system calls from java to windows OS
如何使用Java中的系统调用找到Windows OS的可用系统内存,磁盘空间,CPU使用率?
*在Windows操作系统中
我实际上想做的是,从客户端用户接受文件,并在检查可用空间后将文件保存在服务器中。 我的服务器和客户端使用java tcp套接字程序连接!
您可以使用以下程序获得一些有限的信息。 在同一个论坛中,其他人已经回答了这个问题,而我只是在复制相同的内容。
import java.io.File;
public class MemoryInfo {
public static void main(String[] args) {
/* Total number of processors or cores available to the JVM */
System.out.println("Available processors (cores): " +
Runtime.getRuntime().availableProcessors());
/* Total amount of free memory available to the JVM */
System.out.println("Free memory (bytes): " +
Runtime.getRuntime().freeMemory());
/* This will return Long.MAX_VALUE if there is no preset limit */
long maxMemory = Runtime.getRuntime().maxMemory();
/* Maximum amount of memory the JVM will attempt to use */
System.out.println("Maximum memory (bytes): " +
(maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
/* Total memory currently in use by the JVM */
System.out.println("Total memory (bytes): " +
Runtime.getRuntime().totalMemory());
/* Get a list of all filesystem roots on this system */
File[] roots = File.listRoots();
/* For each filesystem root, print some info */
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());
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.