是否有可能在java中检测处理器架构? [英] Is it possible to detect processor architecture in java?

查看:301
本文介绍了是否有可能在java中检测处理器架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在java中检测处理器架构?像x86或sun SPARC等?如果是这样,我将如何去做?

Is it possible to detect processor architecture in java? like x86 or sun SPARC, etc? If so, how would I go about doing it?

推荐答案

你可以试试 System.getenv()获取环境变量,使用 PROCESSOR_ARCHITECTURE 获取CPU架构的关键:

You can try the System.getenv() to get environment variables, use the PROCESSOR_ARCHITECTURE Key to get the CPU-architechture:

System.out.println(System.getenv("PROCESSOR_ARCHITECTURE"));

或64位的情况:

System.out.println(System.getenv("PROCESSOR_ARCHITEW6432"));

另一种方式是使用os.arch系统属性

The other way would be to use the "os.arch" system property:

System.getProperty("os.arch");

您可能需要在使用 System.getProperty(之前获取操作系统os.name)因为这是操作系统依赖的,因为QMuhammad在他的回答中提到过。

and you may need to get the OS before using System.getProperty("os.name") since this is OS dependent as QMuhammad mentioned in his answer.

注意那个


系统属性和环境变量都是
概念上名称和值之间的映射。这两种机制都可以是
,用于将用户定义的信息传递给Java进程。

System properties and environment variables are both conceptually mappings between names and values. Both mechanisms can be used to pass user-defined information to a Java process.

相关链接:

这篇关于是否有可能在java中检测处理器架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆