只是获取连接到系统的USB设备的名称? [英] just get the names of USB devices attached to a system?
问题描述
是否有任何系统调用或操作系统特定的功能可以被Java调用以获取所连接的USB设备的名称?
Aren't there any system calls or OS specific functions that can be called by Java to get just the names of the USB devices attached?
我见过这里可能只有6-7个问题,但每个人都提到了C ++函数 GetRawInputDeviceList()
等,它们不符合跨平台的要求。适用于C#或C ++中的Windows或仅适用于Linux。
I've seen probably 6-7 questions here only, but everyone mentions the C++ functions GetRawInputDeviceList()
etc, and they are not cross-platform compliant. Either for Windows in C# or C++ or for Linux only.
但我在Java工作。此外,这需要跨平台。
Atleast,它需要适用于Windows,Linux和Mac。我也可以使用terminal / shell / command-prompt命令。我想我可以用Java运行它们。
But I'm working in Java. Also, this needs to be cross platform. Atleast, it needs to be working for Windows,Linux and Mac. I can work with terminal/shell/command-prompt commands also. I guess I can run them with Java.
我试过 getFileSystemView
和 listRoots
。但是他们给出了所有驱动器的名称[dvd,hdd分区,软盘等]。
I've tried getFileSystemView
and listRoots
. But they give out names of all drives [dvd, hdd partitions,floppy etc].
我只需要获得USB设备。
I need to get only USB devices.
请不要提及jUSB或JSR080。原因:
Please don't mention jUSB or JSR080. Why:
jUSB: 访问USB设备目前要求它们连接到GNU / Linux主机系统
javax.usb: pre-alpha Windows实现未经认证且需要内核驱动程序。
usb4java: 基本上,它只是实现了JSR80而不需要抽象,也许
虽然老实说我没有尝试过libusb,因为它是用C ++编写的。
Although to be honest I haven't tried libusb since it is in C++.
如果你是提到API,提到经过全面测试和试用的API,可以在Linux,Windows和Mac上运行。
如果不是这样,我就不会提出这个问题。我在很多其他帖子上看到了jUSB,javax.usb等的提及。
If you are going to mention APIs, mention completely tested and tried ones, that work across Linux,Windows and Mac. If that wasn't the case, I wouldn't have put this question up. I've seen the mention of jUSB, javax.usb, etc on many other posts.
推荐答案
你可以使用 jUsb
适用于Linux的 API 。
You can use the jUsb
API, for Linux.
或者您可以使用进程$ c在Linux中启动
终端
$ c> class,并运行
并捕获
ls -la / dev / disk / by-id / usb - * stdout
知道结果。
Or you could launch the terminal
in Linux using the Process
class, and run
ls -la /dev/disk/by-id/usb-*
and catch the stdout
to know the results.
对于Windows,你可以试试这个:如何使用PowerShell查找我的USB闪存盘的路径
For Windows, you can try this : How to find my USB flash drive's path with PowerShell
编辑:
对于Windows,另一个有用的实用程序是 devcon.exe
。
For Windows, another helpful utility is the devcon.exe
.
有关详情,请查看此。
编辑2:
对于Mac,您可以使用<$启动终端
c $ c>处理类,并运行 system_profiler SPUSBDataType
EDIT 2:
For Mac, you could launch the terminal
using the Process
class, and run system_profiler SPUSBDataType
这篇关于只是获取连接到系统的USB设备的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!