gpt4 book ai didi

javax.usb.UsbException : Properties file javax. 未找到 usb.properties

转载 作者:行者123 更新时间:2023-11-30 09:46:57 44 4
gpt4 key购买 nike

我使用以下代码获取连接到系统的 USB 设备的制造商代码。我添加了 jsr80-1.0.1 jar 。我收到以下错误 javax.usb.UsbException:

Properties file javax.usb.properties not found.

有什么建议吗?

import java.io.UnsupportedEncodingException;
import java.util.*;
import javax.usb.*;

public class USBListener {
public static void main(String[] args) {
try{
UsbServices services = UsbHostManager.getUsbServices();
UsbHub root = services.getRootUsbHub();
listDevices(root);
} catch (Exception e) {
System.out.println(e);
}
}

public static void listDevices(UsbHub hub) throws UnsupportedEncodingException, UsbException {
List devices = hub.getAttachedUsbDevices();
Iterator iterator = devices.iterator();
while(iterator.hasNext()) {
UsbDevice device = (UsbDevice)iterator.next();
describe(device);
if(device.isUsbHub()) {
System.out.println("is hub");
}
}
}

public static void describe(UsbDevice device)
throws UnsupportedEncodingException, UsbException {
UsbDeviceDescriptor descriptor = device.getUsbDeviceDescriptor();
byte manufacturerCode = descriptor.iManufacturer();
System.out.println("Manufacturer index: " + manufacturerCode);
System.out.println("Manufacturer String: " + device.getString(manufacturerCode));
System.out.println("USB version: " + decodeBCD(descriptor.bcdUSB()));
System.out.println("Maximum control packet size: " + descriptor.bMaxPacketSize0());

}

public static String decodeBCD(short bcd) {
int upper = (0xFF00 & bcd) >> 8;
int middle = (0xF0 & bcd) >> 4;
int lower = 0x0F & bcd;
return upper + "." + middle + "." + lower;
}
}

最佳答案

您的类路径中需要此文件。来自文档:

The javax.usb.properties file is a Java properties file that is required by the API implementation loader class. The properties file must be loadable by normal means (i.e. it must be in the CLASSPATH) and it must contain the property javax.usb.services. This property must be defined. Its value must be the fully qualified class name of a class that implements the interface javax.usb.UsbServices. This class will be loaded as the implementation of javax.usb.

此外,如果您看到此错误,您可能还没有实现 javax.usb:

You need a javax.usb implementation; the file is provided by all javax.usb implementations

参见此处:http://javax-usb.sourceforge.net/faq.html#what_is_properties_file

关于javax.usb.UsbException : Properties file javax. 未找到 usb.properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6913399/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com