java怎么读取硬件信息
你们知道怎么用Java读取硬件信息吗?下面是学习啦小编带来的关于java怎么读取硬件信息的内容,欢迎阅读!
java怎么读取硬件信息?
把这个方法放到你的类下边
public void testGetSysInfo() {
//这个是信息变量
String address = "";
//获得系统名称
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows")) {
//抓异常
try {
//定义dos命令
String command = "cmd.exe /c ipconfig /all";
//执行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怎么读取硬件信息文章内容的人还看: