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 anzahlZeichen = brdr.read(buffer, 0, 200);
            String nachricht = new String(buffer, 0, anzahlZeichen);
            byte[] in = nachricht.getBytes("ISO-8859-1");
            for (int counter = 0; counter < nachricht.length(); counter++) {
                System.out.println(in);
            }
            if (nachricht != null)
                answer();
            System.out.println(nachricht);

        } catch (IOException ioe) {
            done = true;
        }
    }

    return null;
}


我想将字符串nachricht转换为Byte [] in,但我不明白。有人可以帮忙吗?我只收到数字,没有单词或字母。也欢迎使用另一种方法。我在System.out.println(nachricht)上得到的全部是[B@41c04778的七倍,但是我应该得到01 02 03 04 05 06 07

最佳答案

您的问题是第System.out.println(in)

应该是System.out.println(in[counter]);

关于java - 从String转换为byte []时遇到问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15067883/

10-09 19:37