我只是运行一些代码来获取我的计算机上的可用端口列表,当我有 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());
}
}
}
输出:假