Issues receiving in RXTX

后端 未结 6 1780
慢半拍i
慢半拍i 2020-12-08 17:47

I\'ve been using RXTX for about a year now, without too many problems. I just started a new program to interact with a new piece of hardware, so I reused the connect() metho

6条回答
  •  隐瞒了意图╮
    2020-12-08 18:14

    If anyone is still getting java.io.IOException: Underlying input stream returned zero bytes after you've read your characters using br.readline() for RXTX (even when you are checking first to see if br.readline() == null), just do this simple fix with a try/catch:

    String line;
    while (true){   
        try{
            line = br.readLine();
        }catch(IOException e){
            System.out.println("No more characters received");
            break;
        }
        //Print the line read
        if (line.length() != 0) 
            System.out.println(line);
    }
    

    I've done some searching and it appears that this is the best/easiest way to get around this problem.

    EDIT : I take that back. I tried this and still ended up having some problems. I'd recommend working with the raw InputStream directly, and implementing your own read/readLine method using InputStream.read(). That worked for me.

提交回复
热议问题