How To Check Window’s Opened Comm Port using Java

On my latest project, i need to connect my java application to a GSM Modem, in order to sending and receiving SMS text. But before my application connected to opened comm port, i need to check which port number is opened. So this is a small java class to check my opened comm port. Btw, im using rtxt libraries to help me communicate with the opened port.

import java.util.Enumeration;

public class Main {
    private void doSomething() {
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements()) {
            CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
    public static void main(String[] args) {
        Main main = new Main();

Dont forget to add rxtx libraries your java’s path. You can find the Window’s installation path, here.

Hope it helps other, have fun 🙂

No Comments

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked