java - 如何知道连接到系统的输入设备有哪些

标签 java hardware

我只是想知道连接到系统的输入设备和输出设备是什么。有没有使用java获取输入/输出设备信息的api?

编辑

独立于任何操作系统。

请提出建议。

最佳答案

要查找连接到系统的 USB 设备,您可以使用 jUSB 。这个article有关于如何使用 api 的更深入的信息。特别是,要查找所有 USB 设备(对文章稍作修改):

Host host = HostFactory.getHost();
// Obtain a list of the USB buses available on the Host.
Bus[] bus  = host.getBusses();

// Traverse through all the USB buses.
for (int i = 0; i < bus.length; i++) {
    // Access the root hub on the USB bus and obtain the number of USB ports available on the root hub.
    Device root = bus[i].getRootHub();
    int totalPorts = root.getNumPorts();

    // Traverse through all the USB ports available on the 
    // root hub. It should be mentioned that the numbering 
    // starts from 1, not 0.
    for (int j=1; j<=total_port; j++) {
        // Obtain the Device connected to the port.
        Device device = root.getChild(j);
        if (device != null) {
                    // USB device available, do something here.
        }
    }
}

同样,您可以使用 MIDI 系统的 api 来查找连接了哪些 MIDI 设备,请参阅 the java tutorials了解更多信息。

关于java - 如何知道连接到系统的输入设备有哪些,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14293956/

相关文章:

java游戏-光滑的滚动条-玩家不能移动

java - 多线程时我需要多少个处理程序

java - 带有最终访问修饰符的 char 和 byte - java

.net - SMS网关设备

powershell - 在 Windows 上获取 CMOS 电池状态信息

.net - 从 Internet Explorer 访问硬件

caching - 脏缓存行和页面驱逐

java - 另一种打印我的方法的方法?

java - 如何解决这个问题关闭这个 "FileOutputStream"

hardware - 移位寄存器与多路复用器