gpt4 book ai didi

java - BufferedReader直接转byte[]

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:00:45 24 4
gpt4 key购买 nike

我下面的 BufferedReader 是否有可能将输入直接放入 byte[]?

public static Runnable reader() throws IOException {
Log.e("Communication", "reader");
din = new DataInputStream(sock.getInputStream());
brdr = new BufferedReader(new InputStreamReader(din), 300);
boolean done = false;
while (!done) {
try {
char[] buffer = new char[200];
int length = brdr.read(buffer, 0, 200);
String message = new String(buffer, 0, length);
btrar = message.getBytes("ISO-8859-1");
int i=0;
for (int counter = 0; counter < message.length(); counter++) {
i++;
System.out.println(btrar[counter] + " = " + " btrar " + i);
}
...

这就是读者的部分,请看

我想直接输入btrar,

最佳答案

is there any possibility my following BufferedReader is able to put the input directly into a byte[]?

任何 Reader 都旨在让您阅读字符,而不是字节。要读取二进制数据,只需使用 InputStream - 如果需要,可以使用 BufferedInputStream 对其进行缓冲。

不太清楚您要做什么,但您可以使用类似的东西:

BufferedInputStream input = new BufferedInputStream(sock.getInputStream());
while (!done) {
// TODO: Rename btrar to something more meaningful
int bytesRead = input.read(btrar);
// Do something with the data...
}

关于java - BufferedReader直接转byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15107104/

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