title: How To Check available port in pc?
body: <p>i want list of available port in pc i am using this code in java but mot getting  response
  i import javax.comm liabrary . please short out my problem</p>
  
  <p>Thanks</p>
  
  <pre><code>import java.util.Enumeration;
  
  import javax.comm.CommPortIdentifier;
  
  
  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.
      Enumeration pList = CommPortIdentifier.getPortIdentifiers();
  
      // Process the list.
      while (pList.hasMoreElements()) {
        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);
        }
      }
    }
  }
  </code></pre>