如何查找操作系统位类型 [英] How to find the OS bit type

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

问题描述

我想知道操作系统类型,是指 64 位操作系统还是 32 位操作系统.但是我从 32 位/64 位可执行文件得到不同的响应,它获取有关操作系统的系统属性

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

我正在从系统属性获取详细信息.我有 64 位机器和操作系统 windows 8.1 X64

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"));


在运行 64bit Executable 时得到以下响应.



While running 64bit Executable getting following response.


操作系统架构:amd64

操作系统名称:Windows 8

操作系统版本:6.2 amd64

数据模型:64


在运行 32bit Executable 时得到以下响应.



While running 32bit Executable getting following response.


操作系统架构:x86

操作系统名称:Windows 8

操作系统版本:6.2 x86

数据模型:32

如何获取操作系统的实际位类型?

推荐答案

最佳解决方案(也是跨平台 IMO)是这里给出的答案:https://stackoverflow.com/a/2269242/1973164

The best solution (which is also cross-platform IMO) is the answer given here: https://stackoverflow.com/a/2269242/1973164

我并不完全相信阅读 os.arch 系统变量.如果用户在 64 位系统上运行 64 位 JVM,它可以工作.如果用户在 64 位系统上运行 32 位 JVM,则它不起作用.

I don't exactly trust reading the os.arch system variable. While it works if a user is running a 64bit JVM on a 64bit system. It doesn't work if the user is running a 32bit JVM on a 64 bit system.

以下代码可用于正确检测 Windows 64 位操作系统.在 Windows 64 位系统上,环境变量Programfiles(x86)"不存在.将被设置.它不会在 32 位系统上设置,java 会将其读取为 null.

The following code works for properly detecting Windows 64-bit operating systems. On a Windows 64 bit system the environment variable "Programfiles(x86)" will be set. It will NOT be set on a 32-bit system and java will read it as null.

boolean is64bit = false;
if (System.getProperty("os.name").contains("Windows")) {
    is64bit = (System.getenv("ProgramFiles(x86)") != null);
} else {
    is64bit = (System.getProperty("os.arch").indexOf("64") != -1);
}

对于 Linux、Solaris 或 Mac 等其他操作系统,我们也可能会遇到此问题.所以这不是一个完整的解决方案.对于 mac 你可能是安全的,因为苹果锁定了 JVM 以匹配操作系统.但是 Linux 和 Solaris 等.他们可能仍然在他们的 64 位系统上使用 32 位 JVM.所以请谨慎使用.

For other operating systems like Linux or Solaris or Mac we may see this problem as well. So this isn't a complete solution. For mac you are probably safe because apple locks down the JVM to match the OS. But Linux and Solaris, etc.. they may still use a 32-bit JVM on their 64-bit system. So use this with caution.

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

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