本文介绍了如何找到OS位类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道的操作系统类型,这意味着它是64位操作系统或32位操作系统。但我正在逐渐从32位/ 64位可执行文件,获取有关OS系统属性不同的反应。

我正在从系统属性的详细信息。我有64位机和操作系统windows 8.1 X64

 OS架构:+ System.getProperty(os.arch));        操作系统名称:+ System.getProperty(os.name));        OS版本:+ System.getProperty(os.version)        数据模型:+ System.getProperty(sun.arch.data.model));


在运行的 64位可执行文件得到下面的响应。


OS架构 AMD64

操作系统名称:Windows 8的

OS版本:6.2 AMD64

数据模型:64


在运行的 32位可执行文件得到下面的响应。


OS架构 86

操作系统名称:Windows 8的

OS版本:6.2 86

数据模型:32


我怎样才能得到实际的操作系统bit类型?


解决方案

  System.getProperty(os.arch);

应该是适用于所有平台,请参见Java系统属性教程以获取更多信息。

但64位Windows平台上会骗JVM的,如果它是一个32位JVM。其实64位Windows会骗任何32位进程对环境,帮助老人32位程序在64位操作系统上正常运行。阅读关于WOW64 MSDN文章以了解更多信息。

作为WOW64的结果,32位JVM调用System.getProperty(os.arch)将返回86。如果你想获得在Windows底层OS的真正架构,使用以下逻辑:

 字符串ARCH = System.getenv(PROCESSOR_ARCHITECTURE);
串wow64Arch = System.getenv(PROCESSOR_ARCHITEW6432);字符串realArch = arch.endsWith(64)
                  || wow64Arch = NULL&放大器;!&安培; wow64Arch.endsWith(64)
                      ? 64:32;

I want to know the OS type, means is it of 64bit os or 32bit os. But I am getting different response from 32bit/64bit executable which getting system properties about OS

I am getting details from system property. and I have 64bit machine and OS windows 8.1 X64

        "OS Architecture : " + System.getProperty("os.arch"));

        "OS Name : " + System.getProperty("os.name"));

        "OS Version : " + System.getProperty("os.version")

        "Data Model : " + System.getProperty("sun.arch.data.model"));


While running 64bit Executable getting following response.


OS Architecture : amd64

OS Name : Windows 8

OS Version : 6.2 amd64

Data Model : 64


While running 32bit Executable getting following response.


OS Architecture : x86

OS Name : Windows 8

OS Version : 6.2 x86

Data Model : 32


How can I get OS actual bit type ?

解决方案
System.getProperty("os.arch");

Should be available on all platforms, see the Java System Properties Tutorial for more information.

But 64 bit Windows platforms will lie to the JVM if it is a 32 bit JVM. Actually 64 bit Windows will lie to any 32 bit process about the environment to help old 32 bit programs work properly on a 64 bit OS. Read the MSDN article about WOW64 for more information.

As a result of WOW64, a 32 bit JVM calling System.getProperty("os.arch") will return "x86". If you want to get the real architecture of the underlying OS on Windows, use the following logic:

String arch = System.getenv("PROCESSOR_ARCHITECTURE");
String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432");

String realArch = arch.endsWith("64")
                  || wow64Arch != null && wow64Arch.endsWith("64")
                      ? "64" : "32";

Reference

这篇关于如何找到OS位类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:40