如何以编程方式确定Java中的操作系统? [英] How do I programmatically determine operating system in Java?

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

问题描述

我想确定我的Java程序以编程方式运行的主机的操作系统(例如:我希望能够根据我是在Windows还是Unix平台上加载不同的属性)。 100%可靠性最安全的方法是什么?

I would like to determine the operating system of the host that my Java program is running programmatically (for example: I would like to be able to load different properties based on whether I am on a Windows or Unix platform). What is the safest way to do this with 100% reliability?

推荐答案

您可以使用:

System.getProperty("os.name")

PS您可能会发现此代码很有用:

P.S. You may find this code useful:

class ShowProperties {
    public static void main(String[] args) {
        System.getProperties().list(System.out);
    }
}

所有它打印出的所有属性都是你的Java实现。它将通过属性为您提供有关Java环境的信息。 : - )

All it does is print out all the properties provided by your Java implementations. It'll give you an idea of what you can find out about your Java environment via properties. :-)

这篇关于如何以编程方式确定Java中的操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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