How do I programmatically determine operating system in Java?

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

    The following JavaFX classes have static methods to determine current OS (isWindows(),isLinux()...):

    • com.sun.javafx.PlatformUtil
    • com.sun.media.jfxmediaimpl.HostUtils
    • com.sun.javafx.util.Utils

    Example:

    if (PlatformUtil.isWindows()){
               ...
    }
    

提交回复
热议问题