1. CPUとメモリ情報を取得します
java.io.inputStreamReader;インポートjava.io.lineNumberreader; Import java.util.arraylist; Import java.util.list; Import mytools.com.sun.managemen T.operatingsystemmxbean; Import mytools.java.io.file; Import; mytools .java.lang.management.managementfactory;/** * Windowsシステム情報(CPU、メモリ、ファイルシステム) * @Author Libing * */public class windowsinfoutil {private static final i nt cputime = 500;パーセント= 100; println(getdisk()); /残りの物理メモリLong freephysicalmemorysize = osmxb.getfreephysicalmemorysize(); % "; return str;} //ファイルシステムを取得しますpublic static list <string> getDisk(){//オペレーティングシステムリスト<String> list = new ArrayList <String>(); for(char c = 'a'; c <= 'z'; string dirname = c+":/"; long free =(long)win.getFreespace(); "; list.add(str);}} return list;} // get cpu usage public static string getcpuratioforwindows(){try {string proccmd = system.getenv(" windir ") +" // s ystem32 // wbem // wbem // /wmic .exeプロセスキャプション、コマンドライン、kernelmodetime、readoperationcount、threadcount、usermodetime、writeoperationccount "; //プロセス情報長い[] c0 = readcp u(runtime.getruntime()。exec(proccmd)); swree cputime)c1 = readcpu(runtime() = C1 [1] -C0 [1]; cpu使用率: "+0+"% ";}} catch(Exception ex){ex.printstacktrace(); return" cpu usage: "+0+"% ";}} // long [] readcpu(long [] new long [2]; LinEnumberReader(IR); Line == null || line()<fault ling} int null; = indexof( "commandline"); line.indexof( "withoperationcount"); long kneltime = 0; ){続行; 、cmdidx、kmtidx -1).trim(); string s2 = substring(line、umtidx、wocidx -1).trim(); 0)idletime = long.valueof(s1).longvalue(); > 0)long.valueof(s1).longvalue(); [1] = kneltime; (); substringは漢字の問題を抱えているので、nullを返します。 PARAM SRC STRING * @PARAM START_IDX Start Coordinate(この座標を含む) * @Param END_IDXカットオフ座標(この座標を含む) * @return */ private Static String Substring(String Src、int start_idx、int end_id x){byte [byte [ b = src .getBytes();2。マシンのIPアドレスを取得します。
Private Static String getipaddress()unknowshostexception {inetaddress.getLocalHost();
3.ネットワークカードアドレスを取得します
public Static string getmacaddress(){string address = ""; . startsWith("Windows")) { try { String command = "cmd.exe /c ipconfig /all"; Process p = Runtime.getRuntime().exec(command); BufferedReader br =ne w BufferedReader(new InputStreamReader(p .getInputStream()); "); index += 2; address = line.substring(index); break;}} br.close(); return address.trim();} catch(ioexception e){}} return address;}4.オペレーティングシステムアカウントを取得します
string osuser = system.getProperty( "user.name");
5.オペレーティングシステムバージョンを取得します
java.util.properties = system.getProperties(); os .arch "); //オペレーティングシステムアーキテクチャストリングosversion = props.getProperty(" os.version "); //オペレーティングシステムバージョン
6.一般的に使用されるいくつかの情報取得方法を整理します
Java.Version Javaランタイム環境バージョン
Java.Vendor Java Runtime Environment Vendor
java.vendor.url javaベンダーのURL
Java.home Javaインストールディレクトリ
java.vm.specification.version java仮想マシン仕様バージョン
java.vm.specification.vendor java仮想マシン仕様ベンダー
java.vm.specification.name java仮想マシン仕様名
java.vm.version java仮想マシンの実装バージョン
java.vm.vendor Java仮想マシン実装ベンダー
java.vm.name java仮想マシンの実装名
java.specification.version javaランタイム環境仕様バージョン
java.specification.vendor Java Runtime Environment Specificationベンダー
Java.specification.Name Javaランタイム環境仕様名
java.class.version javaクラス形式バージョン番号
java.class.path java classpath
java.library.pathライブラリのロード時に検索されたパスのリスト
java.io.tmpdirデフォルトの一時ファイルパス
java.compilerが使用するJITコンパイラの名前
java.ext.dirs 1つ以上の拡張ディレクトリへのパス
OS.Nameオペレーティングシステムの名前
OS.ARCHオペレーティングシステムアーキテクチャ
OS.Versionオペレーティングシステムバージョン
file.separator file separator( "/" in unix systems)
Path.Separator Path Separator( ":" Unix Systems)
line.separator lineセパレーター( "/n" Unix Systems)
user.Nameユーザーのアカウント名
user.homeユーザーのホームディレクトリ
user.dirユーザーの現在の作業ディレクトリ