How do I programmatically determine operating system in Java?

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

    In com.sun.jna.Platform class you can find useful static methods like

    Platform.isWindows();
    Platform.is64Bit();
    Platform.isIntel();
    Platform.isARM();
    

    and much more.

    If you use Maven just add dependency

    
     net.java.dev.jna
     jna
     5.2.0
    
    

    Otherwise just find jna library jar file (ex. jna-5.2.0.jar) and add it to classpath.

提交回复
热议问题