小编Col*_*rie的帖子

Java/Android-将InputStream转换为字符串

我正在通过蓝牙读取来自设备的持续数据流。我想知道如何将这些数据转换为字符串并将其打印出来?缓冲区将包含一个 ASCII 字符串,但当我运行它时,它会打印出整数,我希望能够看到该字符串。

 while (true) {
                try {
                    //read the data from socket stream
                    if(mmInStream != null) {
                       int input = mmInStream.read(buffer);

                       System.out.println(input);
                    }
                    // Send the obtained bytes to the UI Activity
                } catch (IOException e) {
                    //an exception here marks connection loss
                    //send message to UI Activity
                    break;
                }
            }
Run Code Online (Sandbox Code Playgroud)

java android bluetooth inputstream stream

5
推荐指数
1
解决办法
3900
查看次数

标签 统计

android ×1

bluetooth ×1

inputstream ×1

java ×1

stream ×1