int x=0;
Enumeration portList1 = CommPortIdentifier.getPortIdentifiers();
while (portList1.hasMoreElements()) {
x++;
test_buffer[x]=((CommPortIdentifier) portList1.nextElement()).getName();
System.out.println("第"+x+"串口"+test_buffer[x]);
if((test_buffer[x]==null)){
x--;
break;
}
}
test_1=new String[x];
for(int j=0;j<x;j++){
test_1[j]=test_buffer[j+1];
System.out.println("第"+j+"串口:"+test_1[j]);
}
第1串口COM1
第2串口COM2
第3串口LPT1
第4串口LPT2
第0串口:COM1
第1串口:COM2
第2串口:LPT1
第3串口:LPT2
第1串口COM1
第2串口COM2
第3串口LPT1
第4串口LPT2
第0串口:COM1
第1串口:COM2
第2串口:LPT1
第3串口:LPT2
第1串口COM1
第2串口COM2
第3串口LPT1
第4串口LPT2
第0串口:COM1
第1串口:COM2
第2串口:LPT1
第3串口:LPT2
第1串口COM1
第2串口COM2
第3串口LPT1
第4串口LPT2
第0串口:COM1
第1串口:COM2
第2串口:LPT1
第3串口:LPT2
第1串口COM1
第2串口COM2
第3串口LPT1
第4串口LPT2
第0串口:COM1
第1串口:COM2
第2串口:LPT1
第3串口:LPT2