【问题标题】:How do I get what os the computer is running with java? [duplicate]如何获取计算机正在运行的 java 操作系统? [复制]
【发布时间】:2012-11-19 03:21:29
【问题描述】:

可能重复:
How do I programmatically determine operating system in Java?

在 Java 中,我如何获取运行我的 Java 小程序的操作系统类型(Mac、Windows、Linux 等)?

提前致谢 ;D

【问题讨论】:

  • -1;你应该问问你最喜欢的搜索引擎...

标签: java operating-system


【解决方案1】:
public class OpertingSystemInfo 
{
  public static void main(String[] args)
  {
    String nameOS = "os.name";  
    String versionOS = "os.version";  
    String architectureOS = "os.arch";

    System.out.println("\n  The information about OS");
    System.out.println("\nName of the OS: " + System.getProperty(nameOS));
    System.out.println("Version of the OS: " + System.getProperty(versionOS));
    System.out.println("Architecture of THe OS: " + System.getProperty(architectureOS));
  }
}

http://www.roseindia.net/java/beginners/OSInformation.shtml

【讨论】:

  • 谢谢!一个很好的明确答案:D
【解决方案2】:
System.out.println(System.getProperties().get("os.name"));

【讨论】:

    【解决方案3】:

    系统属性os.name 提供操作系统的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-03
      • 2010-12-01
      • 2012-04-18
      • 2019-05-11
      • 1970-01-01
      • 2012-03-11
      • 2021-10-31
      • 2013-07-27
      相关资源
      最近更新 更多