gpt4 book ai didi

java - System.getProperty ("os.name") 和 System.getProperty ("os.version") 在 windows 11 机器中返回 windows 10, 10.0

转载 作者:行者123 更新时间:2023-12-02 15:50:28 26 4
gpt4 key购买 nike

System.getProperty("os.name") and System.getProperty("os.version") returning windows 10, 10.0, in windows 11 machine

如果有人知道无需使用任何命令即可获取 Windows 版本的 Java 代码,请提供帮助或在此处附上 Java 代码。

openjdk version "1.8.0_322"
OpenJDK Runtime Environment Corretto-8.322.06.1 (build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM Corretto-8.322.06.1 (build 25.322-b06, mixed mode)
class Demo
{
public static void main(String g[])
{
System.out.println(" os name = "+System.getProperty("os.name"));
System.out.println(" os version = "+System.getProperty("os.version"));
}
}

输出:

os name = Windows 10
os version = 10.0

最佳答案

在 Java 11 (11.0.15) 和 Java 17 (17.0.3) 上,System.getProperty("os.name") 返回 Windows 11,但是 “os.version” 仍然报告 10.0,因为这实际上是 Microsoft(仍然)用于 Windows 11 的版本。

例如,Windows 系统信息报告:

操作系统名称 Microsoft Windows 11 Pro
版本 10.0.22000 内部版本 22000

这类似于您的屏幕截图中显示的内容。

不幸的是,Java 8 (1.8.0_332) 仍然报告 Windows 10。我查看了 Java 8 中可用的系统属性和环境变量,但似乎没有属性或环境变量可让您检测到您使用的是 Windows 11 而不是 Windows 10。

JDK-8293124 Update OS detection code to recognize Windows 11 的反向移植列表|建议这应该已在 Java 8 更新 8u311、8u321 和 8u331 中修复。但考虑到我在 1.8.0_332 (Temurin) 和 1.8.0_345 (Temurin) 中仍然得到旧结果,此修复已被还原或仅在特定构建(例如 Oracle 的)中可用。它还列出了尚未发布的 openjdk8u362,因此此修复程序可能会在 1.8.0_362 中发布。

关于java - System.getProperty ("os.name") 和 System.getProperty ("os.version") 在 windows 11 机器中返回 windows 10, 10.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72668838/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com