java怎么讀取硬件信息
你們知道怎么用Java讀取硬件信息嗎?下面是學習啦小編帶來的關(guān)于java怎么讀取硬件信息的內(nèi)容,歡迎閱讀!
java怎么讀取硬件信息?
把這個方法放到你的類下邊
public void testGetSysInfo() {
//這個是信息變量
String address = "";
//獲得系統(tǒng)名稱
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows")) {
//抓異常
try {
//定義dos命令
String command = "cmd.exe /c ipconfig /all";
//執(zhí)行dos命令
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
logger.info("mac address:" + address.trim());
} catch (IOException e) {
logger.info("Error:" + e);
}
}
}
看了java怎么讀取硬件信息文章內(nèi)容的人還看: