用Java检测USB驱动器

用Java检测USB驱动器

本文介绍了用Java检测USB驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测Windows,Linux或Mac上何时将USB驱动器连接到计算机?

How can I detect when a USB drive is attached to a computer in Windows, Linux, or Mac?

我在网上看到的唯一方法是对驱动器进行迭代,但是我认为没有一种很好的方法可以跨平台运行(例如,Linux中的File.listRoots()仅返回"/").即使在Windows中,这也会导致从每台设备读取问题,例如需要很长时间才能访问的网络驱动器.

The only way I have seen online to do this is to iterate the drives, but I don't think there is a very good way to do that cross-platform (e.g. File.listRoots() in Linux only returns "/"). Even in Windows this would cause problems reading from every device, such as a network drive that takes a long time to access.

有一个名为jUsb的库,听起来像它在Linux中完成了此任务,但在Windows中不起作用. Windows对此jUsb进行了扩展,但是它要求用户安装dll文件并运行.reg.这些似乎都没有开发多年,所以我希望现在有一个更好的解决方案.当我只想检测连接的设备是否包含我需要的文件时,它们对我的需求也没有帮助.

There is a library called jUsb that sounds like it accomplishes this in Linux, but it doesn't work in Windows. There is also an extension to this called jUsb for Windows, but that requires users to install a dll file and run a .reg. Neither of these seem to be developed for several years, so I'm hoping a better solution exists now. They're also overkill for what I need, when I only want to detect if a device is connected that contains a file I need.

此外,jUsb显然不适用于Java的任何最新版本,因此,这甚至都不是一个选择...

Furthermore, jUsb apparently doesn't work with any recent version of Java, so this isn't even an option...

谢谢

推荐答案

我制作了一个小库来检测Java上的USB存储设备.它可以在Windows,OSX和Linux上运行.看看: https://github.com/samuelcampos/usbdrivedetector

I've made a small library to detect USB storage devices on Java. It works on Windows, OSX and Linux. Take a look at: https://github.com/samuelcampos/usbdrivedetector

这篇关于用Java检测USB驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:58