我只是运行一些代码来获取我的cmputer中的可用端口列表,当我有3个免费的COM端口时,它返回了我的错误.我该如何解决这个问题?
我的代码:
- public static void main(String[] args) {
- //SerialParameters params=new SerialParameters();
- // System.out.println(CommPortIdentifier.PORT_SERIAL );
- Enumeration portList = CommPortIdentifier.getPortIdentifiers();
- System.out.println(portList.hasMoreElements());
- while(portList.hasMoreElements()){
- System.out.println("Has more elements");
- CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
- if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
- System.out.println(portId.getName());
- }
- else{
- System.out.println(portId.getName());
- }
- }
- }
输出:
假