0

Javaからのシステムコールを使用して、使用可能なシステムメモリ、ディスクスペース、Windows OSのCPU使用率を見つける方法は?

*Windowsオペレーティングシステムの場合

私が実際にやりたいのは、、、、クライアントユーザーからファイルを受け取り、使用可能なスペースを確認した後、そのファイルをサーバーに保存することです。私のサーバーとクライアントは、Javatcpソケットプログラムを使用して接続されています。

4

1 に答える 1

1

以下のプログラムを使用して、いくつかの限られた情報を取得できます。これは同じフォーラムの他の誰かによってすでに答えられており、私は同じことを再現しています。

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());
    }
  }
}
于 2013-02-26T06:12:51.033 に答える