Java: Afficher la liste des périphériques USB

Author:

 int,string,static, list, list, iterator, iterator, java
{filelink=29}

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

public class USBLister {

  public static void main(String[] args) throws UsbException {
    UsbServices services = UsbHostManager.getUsbServices();
    UsbHub root = services.getRootUsbHub();
    listPeripherique(root);
  }

  public static void listPeripherique(UsbHub hub) {
    List perepheriques = hub.getAttachedUsbDevices();
    Iterator iterator = perepheriques.iterator();
    while (iterator.hasNext()) {
      UsbDevice perepherique = (UsbDevice) iterator.next();
      System.out.println(perepherique);
      if (perepherique.isUsbHub()) {
        listPeripherique((UsbHub) perepherique);
      }
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *