java代码获取电脑信息,java获取电脑机器码
Java如何获取本地计算机的IP地址和主机名
可以使用 InetAddress.getLocalHost(),代码如下:
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序设计、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了合浦免费建站欢迎大家使用!
import java.net.*;
public class App {
public static void main(String[] args) throws UnknownHostException {
InetAddress local = InetAddress.getLocalHost();
System.out.println("计算机名:" + local.getHostName());
System.out.println("IP:" + local.getHostAddress());
}
}
Java如何取得计算机硬件信息么
可以的
IMonitorService接口:
public interface IMonitorService {
public MonitorInfoBean getMonitorInfoBean() throws Exception;
}
MonitorInfoBean类:
/*采集系统存取数据JavaBean*/
public class MonitorInfoBean implements ComparableMonitorInfoBean {
/** 操作系统. */
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;
java中如何获得计算机的信息。
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得到这些信息
网页题目:java代码获取电脑信息,java获取电脑机器码
本文路径:http://azwzsj.com/article/phgjop.html