如何用JAVA读取,本机硬件信息?

baigy 2004-07-02 10:20:28
如何用JAVA读取,本机硬件信息?

如内存,CPU。

内存占用率,CPU占用率等等。

最好提供通用,夸平台的解决办法。

没准主意的,胡乱点子也接收!统统有分
...全文
296 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
duckula007 2004-07-07
  • 打赏
  • 举报
回复
用API就不能跨平台了,比较麻烦啊!
顺便问一下什么是JNI啊?(我是菜鸟)
fakefakir 2004-07-07
  • 打赏
  • 举报
回复
使用过一份如JohnsonShu(野蛮人)所说方式的代码,是读取自定义环境变量的。希望能有帮助。
public static Properties getEnvVars() {
Process p = null;
Properties envVars = new Properties();
try {
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
// System.out.println(OS);
if (OS.indexOf("windows 9") > -1) {
p = r.exec( "command.com /c set" );
}
else if ( (OS.indexOf("nt") > -1)
|| (OS.indexOf("windows 2000") > -1
|| (OS.indexOf("windows xp") > -1) ) ) {
// thanks to JuanFran for the xp fix!
p = r.exec( "cmd.exe /c set" );
}
else {
// our last hope, we assume Unix (thanks to H. Ware for the fix)
p = r.exec( "env" );
}
BufferedReader br = new BufferedReader
( new InputStreamReader( p.getInputStream() ) );
String line;
while( (line = br.readLine()) != null ) {
int idx = line.indexOf( '=' );
String key = line.substring( 0, idx );
String value = line.substring( idx+1 );
envVars.setProperty( key, value );
}
}
catch (Exception e) {
e.printStackTrace();
// we do not care here. Just no env vars for the user. Sorry.
}
weiliweili 2004-07-07
  • 打赏
  • 举报
回复
如果用jni会不会不安全,这样就可以让外界看到你调用程序的接口,如果是做注册判断的话,很容易被外界将判断信息捕获。Runtime.exec(“dir”)的方法可不可以说清楚一点?是在java里面直接实现,不用调用外部程序吗?
JohnsonShu 2004-07-03
  • 打赏
  • 举报
回复
Runtime.exec("dir")之类的命令,截获输出进行分析
baigy 2004-07-02
  • 打赏
  • 举报
回复
JNI 如何搞啊。两位高手指点指点。

分不够再加,俺还有6000多
eclipse0016 2004-07-02
  • 打赏
  • 举报
回复
只能用JNI了。很难跨平台啊
Computer_lover 2004-07-02
  • 打赏
  • 举报
回复
通过JNI算不算点子

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧