关于windows下使用sigar报错,the device is not ready

服务器环境为windows 32位,已经尝试过将sigar-x86-winnt.dll,sigar-x86-winnt.lib文件放在jdk bin目录下但是还是提示the device is not ready,项目为springboot通过bat文件启动

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sigar是一个跨平台的系统信息收集库,可以用于监控系统资源使用情况、进程信息、文件系统等等。如果要使用Sigar来监听文件变化,可以使用Sigar的文件系统API。 以下是一个简单的示例代码,用于监听指定目录下的文件变化: ```java import org.hyperic.sigar.*; import java.io.File; import java.util.HashMap; import java.util.Map; public class FileMonitor { private static final String DIR_TO_MONITOR = "/path/to/monitor"; private static final long INTERVAL = 1000; // 每隔1秒检查一次 private Sigar sigar; private Map<String, Long> files; public FileMonitor() { sigar = new Sigar(); files = new HashMap<String, Long>(); } public void start() throws SigarException { while (true) { File dir = new File(DIR_TO_MONITOR); if (!dir.exists() || !dir.isDirectory()) { throw new SigarException("Invalid directory: " + DIR_TO_MONITOR); } for (File file : dir.listFiles()) { if (file.isFile()) { String path = file.getAbsolutePath(); long lastModified = file.lastModified(); Long prevModified = files.get(path); if (prevModified == null) { files.put(path, lastModified); } else if (lastModified != prevModified) { System.out.println(path + " has been modified."); files.put(path, lastModified); } } } try { Thread.sleep(INTERVAL); } catch (InterruptedException e) { // Ignore } } } public static void main(String[] args) throws SigarException { FileMonitor monitor = new FileMonitor(); monitor.start(); } } ``` 该示例代码使用Sigar的`Sigar.getFilesystemList()`方法获取文件系统列表,然后使用`Sigar.getDirStat()`方法获取指定目录下的文件信息。每隔一段时间,程序会检查文件的修改时间是否发生了变化,如果有变化就输出文件路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值