本文介绍了是否有可能在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?
推荐答案
你可以试试获取环境变量,使用 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.
注意:
相关链接:
- System.getenv() doc
- ChrisH's answer
- Why %processor_architecture% always returns x86 instead of AMD64
- Java's "os.arch" System Property is the Bitness of the JRE, NOT theOperating System
- Finding out sytem architecture using Java
这篇关于是否有可能在java中检测处理器架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!