gpt4 book ai didi

java - 将InputStream的内容打印到LogCat

转载 作者:行者123 更新时间:2023-12-01 11:39:25 24 4
gpt4 key购买 nike

我这里有这个功能:

public void read() {
byte buffer[] = new byte[1024];
int bytes;

try {
bytes = iStream.read(buffer);
//Send what got read to LogCat here
} catch(IOException e) {
//TODO: something
}
}

它从BluetoothSocket 输入流读取。如何显示 LogCat 读取的内容?

最佳答案

您可以使用以下方式打印整个字节数组:

Log.i(TAG,new String(buffer, "UTF-8")); // for UTF-8 encoding

您可以使用 Charset 类中的编码:Supported Encodings

关于java - 将InputStream的内容打印到LogCat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29664269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com