Question

how to write char array to java socketchannel. I am not able to write the char data to socketchannel as it takes ByteBuffer.

Était-ce utile?

La solution

Have you tried using putChar method of ByteBuffer?

ByteBuffer buf = ByteBuffer.allocate(1024);

for (char ch : myChars) {
  buf.putChar(ch);
}

Autres conseils

Several ways eg

char[] c = {'1', '2'};
String str = new String(c);
ByteBuffer bb = Charset.defaultCharset().encode(str);

or

ByteBuffer.wrap(str.getBytes());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top