How do I programmatically determine operating system in Java?

后端 未结 19 3073
眼角桃花
眼角桃花 2020-11-22 04:56

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 propertie

19条回答
  •  感动是毒
    2020-11-22 05:11

    You can use:

    System.getProperty("os.name")
    

    P.S. You may find this code useful:

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

    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. :-)

提交回复
热议问题