1 package test; 2 import java.util.Enumeration; 3 4 import javax.comm.*; 5 6 class serialPort{ 7 8 public void ListPort(){ 9 Enumeration en = CommPortIdentifier.getPortIdentifiers(); 10 CommPortIdentifier portID; 11 while(en.hasMoreElements()){ 12 portID = (CommPortIdentifier)en.nextElement(); 13 if(portID.getPortType() == CommPortIdentifier.PORT_SERIAL){ 14 System.out.println(portID.getName()); 15 16 } 17 } 18 19 } 20 21 } 22 public class protect_one { 23 24 public static void main(String[] args) { 25 serialPort serialport = new serialPort(); 26 serialport.ListPort(); 27 28 } 29 }