java中如何获得计算机的信息。
用java如何获得计算机的硬件信息?如网卡号,cup编号,硬盘编号,主板编号。等(然后写到指定的文件下,这个我会写)。主要是获得硬件信息,最好有原码,如果没有给点提示也好...
用java如何获得计算机的硬件信息?如网卡号,cup编号,硬盘编号,主板编号。等(然后写到指定的文件下,这个我会写)。
主要是获得硬件信息,最好有原码,如果没有给点提示也好。谢谢了,先给20分吧,如果问题解决了,再加分。
网卡号,cpu编号,硬盘编号,主板编号,这个可以获得吗?!!
它们对应的key是什么。就是说那个key对应网卡编号,那个key对应cpu编号? 展开
主要是获得硬件信息,最好有原码,如果没有给点提示也好。谢谢了,先给20分吧,如果问题解决了,再加分。
网卡号,cpu编号,硬盘编号,主板编号,这个可以获得吗?!!
它们对应的key是什么。就是说那个key对应网卡编号,那个key对应cpu编号? 展开
2个回答
展开全部
System.getProperties()
返回的是Properties
Properties 类表示了一个持久的属性集
以下的代码就可以把Properties的内容读出来
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String Property = props.getProperty (key);
System.out.println(key+Property);
}
} catch (Exception e) {
e.printStackTrace();
}
对于补充的回答:
java不能直接得到楼主需要的信息,但是可以采用JNI,即调用C程序,让C得到这些信息
返回的是Properties
Properties 类表示了一个持久的属性集
以下的代码就可以把Properties的内容读出来
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String Property = props.getProperty (key);
System.out.println(key+Property);
}
} catch (Exception e) {
e.printStackTrace();
}
对于补充的回答:
java不能直接得到楼主需要的信息,但是可以采用JNI,即调用C程序,让C得到这些信息
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
IMonitorService接口:
public interface IMonitorService {
public MonitorInfoBean getMonitorInfoBean() throws Exception;
}
MonitorInfoBean类:
/*采集系统存取数据JavaBean*/
public class MonitorInfoBean implements Comparable<MonitorInfoBean> {
/** 操作系统. */
private String osName;
/** 总的物理内存. */
private float totalMemorySize;
/** 已使用的物理内存. */
private float usedMemory;
/** cpu使用率. */
private double cpuRatio;
/** 主机IP地址 */
private String mIpAddress;
/** 数据存储时间 */
private String dDateTime;
/**内存使用率*/
private float memoryRatio;
/**linux下Buffers内存*/
private float buffersMemory;
/**linux下Cached内存*/
private float cachedMemory;
public float getBuffersMemory() {
return buffersMemory;
}
public float getCachedMemory() {
return cachedMemory;
}
public String getDDateTime() {
return dDateTime;
}
public void setDDateTime(String dateTime) {
dDateTime = dateTime;
}
public String getMIpAddress() {
return mIpAddress;
}
public void setMIpAddress(String ipAddress) {
mIpAddress = ipAddress;
}
public String getOsName() {
return osName;
}
public void setOsName(String osName) {
this.osName = osName;
}
public float getTotalMemorySize() {
return totalMemorySize;
}
public void setTotalMemorySize(float totalMemorySize) {
this.totalMemorySize = totalMemorySize;
}
public float getUsedMemory() {
return usedMemory;
}
public void setUsedMemory(long usedMemory) {
this.usedMemory = usedMemory;
}
public double getCpuRatio() {
return cpuRatio;
}
public void setCpuRatio(double cpuRatio) {
this.cpuRatio = cpuRatio;
}
public int compareTo(MonitorInfoBean m) {
String stra = this.getDDateTime();
String strb = m.getDDateTime();
Timestamp a = Timestamp.valueOf(stra);
Timestamp b = Timestamp.valueOf(strb);
if (a.before(b)) {
return -1;
} else if (a.after(b)) {
return 1;
} else {
return 0;
}
}
public float getMemoryRatio() {
return memoryRatio;
}
public void setMemoryRatio(float memoryRatio) {
this.memoryRatio = memoryRatio;
}
public void setUsedMemory(float usedMemory) {
this.usedMemory = usedMemory;
}
public void setBuffersMemory(float buffersMemory) {
this.buffersMemory = buffersMemory;
}
public void setCachedMemory(float cachedMemory) {
this.cachedMemory = cachedMemory;
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.StringTokenizer;
import sun.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
/*采集系统采集数据实现类*/
/**
* @author Administrator
*
*/
参考资料http://www.iteye.com/problems/71992
public interface IMonitorService {
public MonitorInfoBean getMonitorInfoBean() throws Exception;
}
MonitorInfoBean类:
/*采集系统存取数据JavaBean*/
public class MonitorInfoBean implements Comparable<MonitorInfoBean> {
/** 操作系统. */
private String osName;
/** 总的物理内存. */
private float totalMemorySize;
/** 已使用的物理内存. */
private float usedMemory;
/** cpu使用率. */
private double cpuRatio;
/** 主机IP地址 */
private String mIpAddress;
/** 数据存储时间 */
private String dDateTime;
/**内存使用率*/
private float memoryRatio;
/**linux下Buffers内存*/
private float buffersMemory;
/**linux下Cached内存*/
private float cachedMemory;
public float getBuffersMemory() {
return buffersMemory;
}
public float getCachedMemory() {
return cachedMemory;
}
public String getDDateTime() {
return dDateTime;
}
public void setDDateTime(String dateTime) {
dDateTime = dateTime;
}
public String getMIpAddress() {
return mIpAddress;
}
public void setMIpAddress(String ipAddress) {
mIpAddress = ipAddress;
}
public String getOsName() {
return osName;
}
public void setOsName(String osName) {
this.osName = osName;
}
public float getTotalMemorySize() {
return totalMemorySize;
}
public void setTotalMemorySize(float totalMemorySize) {
this.totalMemorySize = totalMemorySize;
}
public float getUsedMemory() {
return usedMemory;
}
public void setUsedMemory(long usedMemory) {
this.usedMemory = usedMemory;
}
public double getCpuRatio() {
return cpuRatio;
}
public void setCpuRatio(double cpuRatio) {
this.cpuRatio = cpuRatio;
}
public int compareTo(MonitorInfoBean m) {
String stra = this.getDDateTime();
String strb = m.getDDateTime();
Timestamp a = Timestamp.valueOf(stra);
Timestamp b = Timestamp.valueOf(strb);
if (a.before(b)) {
return -1;
} else if (a.after(b)) {
return 1;
} else {
return 0;
}
}
public float getMemoryRatio() {
return memoryRatio;
}
public void setMemoryRatio(float memoryRatio) {
this.memoryRatio = memoryRatio;
}
public void setUsedMemory(float usedMemory) {
this.usedMemory = usedMemory;
}
public void setBuffersMemory(float buffersMemory) {
this.buffersMemory = buffersMemory;
}
public void setCachedMemory(float cachedMemory) {
this.cachedMemory = cachedMemory;
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.StringTokenizer;
import sun.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
/*采集系统采集数据实现类*/
/**
* @author Administrator
*
*/
参考资料http://www.iteye.com/problems/71992
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询