I'm writing a client server program in which I have to send byte[]
. So, I'm using following code:
byte[] b = {}; //byte array of size 10
w2.write(new String(b, "utf-8") + "\n"); //exceptions etc. are handled
On the receiving side:
String s = r.readLine();
byte[] g = s.getBytes("utf-8");
//Now, when I print the string here, the o/p seems
//to be the same as on the sending side but g.length is now 14 here.
I'm printing the byte array converting it to string by new String(byte array[], "utf-8")
It prints some unreadable characters too, but they match (So I don't think there is the problem)
What can the reason be for this kind of behavior?
This is how reader and writer are declared:
c = (SSLSocket) f.createSocket("127.0.0.1", 24910);
w = new BufferedWriter(new OutputStreamWriter(c.getOutputStream()));
r = new BufferedReader(new InputStreamReader(c.getInputStream()));