8

我的以下 BufferedReader 是否有可能将输入直接放入字节 []?

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,

4

1 回答 1

27

我的以下 BufferedReader 是否有可能将输入直接放入字节 []?

AnyReader旨在让您读取字符,而不是字节。要读取二进制数据,只需使用InputStream- usingBufferedInputStream来缓冲它。

目前还不清楚你要做什么,但你可以使用类似的东西:

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...
}
于 2013-02-27T08:16:08.297 回答