用Java获取电池电量 [英] Get battery level in Java
本文介绍了用Java获取电池电量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作一个显示我的mac OS X当前电池电量的java应用程序。
I would like to make a java app that shows the current battery level of my mac OS X.
我读过获取操作系统级系统信息,并想知道如何修改它以使其显示当前%电池
I have read get OS-level system information and was wondering how I could modify this to make it display the current % of battery
谢谢
推荐答案
我认为你有两种选择。
I think you have two options.
一种是使用JNI调用本机代码来获取电池电量。
One is to use JNI to invoke native code to get the battery level.
另一种是使用 System.exec $ c来调用应用程序
pmset
$ c>在java中并解析输出。我认为检索电池电量的参数是 pmset -g ps
但你最好查看手册页
The other is to invoke the application pmset
using System.exec
in java and parse the output. I think the arguments to retrieve the battery level is pmset -g ps
but you better check the man page
这篇关于用Java获取电池电量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文