首页 > 编程语言 > 详细

JAVA监控windows7系统的USB插拔事件

时间:2018-11-10 11:41:15      阅读:337      评论:0      收藏:0      [点我收藏+]
package usb;

import java.io.File;

public class UsbDevice {
//扫描系统的盘符
File[] root = File.listRoots();

public static void main(String[] args) {
new UsbDevice().searchUSB();
}

public void searchUSB() {
System.out.println("扫描系统...");
while (true) {
//循环里扫描盘符
File[] files = File.listRoots();
//比较长度
if (files.length > root.length) {
//重新赋值给系统root 相当于加1
root = File.listRoots();
System.out.println("插入");
} else if (files.length < root.length) {
//重新赋值给系统root 相当于减1
root = File.listRoots();
System.out.println("拔出");
}
}

}
}

JAVA监控windows7系统的USB插拔事件

原文:https://www.cnblogs.com/maocai2018/p/9938629.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!