title: how to count Usb port using java?
body: <p>I want to detect list of USB Ports which are free <em>(not occupied)</em> in system to while I checked with <code>CommPortIdentifier.getPortIdentifiers()</code> while this returns me Enumeration with 0 elements
  I'd add librxtxcomm.jar too in classpath.</p>
  
  <p>This should return each Port detail</p>
  
  <pre><code>Enumeration pList = CommPortIdentifier.getPortIdentifiers(); 
  System.out.println(pList.hasMoreElements());
  </code></pre>
  
  <p>this returns 0 mean no List/Enumeration.</p>
  
  <p>Rest Code :</p>
  
  <pre><code>public class CommPortLister{
  
      /** Simple test program. */
      public static void main(String[] ap) {
          new CommPortLister().list();
      }
  
      /** Ask the Java Communications API * what ports it thinks it has. */
      protected void list() {
          // get list of ports available on this particular computer, by calling static method in CommPortIdentifier.
  
          System.out.println("");
          Enumeration pList = CommPortIdentifier.getPortIdentifiers();
          System.out.println("Before While");
          // CommPortIdentifier.getPortIdentifiers(); 
          // Process the list.
          System.out.println(pList.hasMoreElements());
  
          while (pList.hasMoreElements()) {
              System.out.println("While Loop");
              CommPortIdentifier cpi = (CommPortIdentifier) pList.nextElement();
              System.out.print("Port " + cpi.getName() + " ");
              if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                  System.out.println("is a Serial Port: " + cpi);
              } else if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL)  {
                  System.out.println("is a Parallel Port: " + cpi);
              } else  {
                  System.out.println("is an Unknown Port: " + cpi);
              }
          }
          System.out.println("After While");
      }
  }
  </code></pre>
  
  <p>Code to detect USB port while i am unable to detect USB Port</p>