我正在开发一个 USB 读取 Java 程序来获取连接的 USB 设备的名称。这是我写的代码:
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.usb.*;
import javax.usb.UsbDevice;
import javax.usb.UsbDisconnectedException;
import javax.usb.UsbException;
import javax.usb.UsbHostManager;
import javax.usb.UsbHub;
import javax.usb.UsbServices;
public class ListUsbDevices {
public static void main(String[] args) throws SecurityException, UsbException, UnsupportedEncodingException, UsbDisconnectedException {
UsbServices services = UsbHostManager.getUsbServices();
UsbHub rootHub = services.getRootUsbHub();
List<UsbDevice> devices = rootHub.getAttachedUsbDevices();
if (devices.size() > 0) {
System.out.println("USB devices found.");
} else {
System.out.println("No USB devices found.");
}
for (UsbDevice device : devices) {
System.out.println("\tProduct String " + device.getProductString());
System.out.println("\tManufacturer String " + device.getManufacturerString());
System.out.println("\tSerial Number " + device.getSerialNumberString());
}
}
}
当我编译这个程序时,它会显示这个警告:
Note: ListUsbDevices.java uses unchecked or unsafe operations. Recompile with -Xlint:unchecked for details.
我用 重新编译-Xlint:unchecked
,它显示了这一点:
ListUsbDevices.java:21: warning: [unchecked] unchecked conversion found : java.util.L required: java.util.List<javax.usb.UsbDevice> List<UsbDevice> devices = rootHub.getAttachedUsbDevices(); ^.
但是创建了类文件。
当我运行这个程序时,我得到了这个异常:
Exception in thread "main" javax.usb.UsbException: Properties file javax.usb.properties not found.
我该如何解决这个问题?如何在 Mac 中设置属性文件?我已经用这个设置了 CLASSPATH:
export CLASSPATH=.:/Users/sakkisetty/Documents/jsr80-1.0.1.jar
但我不确定这是否有效。任何指针将不胜感激。