Your problem is lineSystem.out.println(in)
It should be System.out.println(in[counter]);
Question
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;
}
i want to convert the String nachricht
to the Byte[] in
but i dont get it. Could anyone help pls? I am just receiving Numbers, no words or letters. Another method is welcome, too. All i get at System.out.println(nachricht)
is seven times[B@41c04778
but i should get 01 02 03 04 05 06 07
.
Solution
Your problem is lineSystem.out.println(in)
It should be System.out.println(in[counter]);
OTHER TIPS
This
[B@41c04778
indicates you're printing an array ([) of bytes (B).
Java arrays don't have a useful toString()
implementation. The above is useful to understand since you'll do the same in the future. Obvious mnemonics exist for other primitive types.