我的以下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,
最佳答案
任何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...
}