I am trying to use java to detect when a USB is inserted and to read from it. I am currently using javax.usb to try to accomplish this however I get this error (line 11) when running my program
javax.usb.UsbException: The property javax.usb.services is not defined as the implementation class of UsbServices
I have inserted the javax.usb.properties file in the top directory of the jar (which seemed to solve my previous error)
Here is my code
import java.util.Iterator;
import java.util.List;
import javax.usb.*;
public class Main {
public static void main(String[] args) {
try {
UsbServices serv = UsbHostManager.getUsbServices();
UsbHub root = serv.getRootUsbHub();
List devices = root.getAttachedUsbDevices();
Iterator itr = devices.iterator();
while (itr.hasNext()){
UsbDevice dev = (UsbDevice) itr.next();
if (dev.isUsbHub()){
System.out.println("Is USB Hub");
}
}
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UsbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Thank you for your help.