Get OS-level system information

后端 未结 16 1993
情话喂你
情话喂你 2020-11-22 02:02

I\'m currently building a Java app that could end up being run on many different platforms, but primarily variants of Solaris, Linux and Windows.

Has anyone been abl

16条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 02:28

    Add OSHI dependency via maven:

    
        com.github.dblock
        oshi-core
        2.2
    
    

    Get a battery capacity left in percentage:

    SystemInfo si = new SystemInfo();
    HardwareAbstractionLayer hal = si.getHardware();
    for (PowerSource pSource : hal.getPowerSources()) {
        System.out.println(String.format("%n %s @ %.1f%%", pSource.getName(), pSource.getRemainingCapacity() * 100d));
    }
    

提交回复
热议问题