How do I programmatically determine operating system in Java?

后端 未结 19 2913
眼角桃花
眼角桃花 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:22

    I think following can give broader coverage in fewer lines

    import org.apache.commons.exec.OS;
    
    if (OS.isFamilyWindows()){
                    //load some property
                }
    else if (OS.isFamilyUnix()){
                    //load some other property
                }
    

    More details here: https://commons.apache.org/proper/commons-exec/apidocs/org/apache/commons/exec/OS.html

提交回复
热议问题