title: Detect plugged usb and read its files in linux using java
body: <p>I've been trying to:</p>
  
  <ol>
  <li>detect a live mounted usb stick</li>
  <li>read its files. </li>
  </ol>
  
  <p>Using usb4java, I was able to fulfill part 1. However usb4Java returns devices and I don't see how I could access the device's files.</p>
  
  <p>This is the code that allows the detection (You can find the complete example on: <a href="https://github.com/usb4java/usb4java-examples/blob/master/src/main/java/org/usb4java/examples/HotPlug.java" rel="nofollow noreferrer">HotPlug example</a>)</p>
  
  <pre><code>public int processEvent(Context context, Device device, int event,
      Object userData) {
    DeviceDescriptor descriptor = new DeviceDescriptor();
    int result = LibUsb.getDeviceDescriptor(device, descriptor);
    if (result != LibUsb.SUCCESS) {
      throw new LibUsbException("Unable to read device descriptor",
          result);
    }
    System.out.format("%s: %04x:%04x%n",
        event == LibUsb.HOTPLUG_EVENT_DEVICE_ARRIVED ? "Connected" :
            "Disconnected",
        descriptor.idVendor(), descriptor.idProduct());
    return 0;
  }
  </code></pre>