문제

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

도움이 되었습니까?

해결책

Have you tried using putChar method of ByteBuffer?

ByteBuffer buf = ByteBuffer.allocate(1024);

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

다른 팁

Several ways eg

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

or

ByteBuffer.wrap(str.getBytes());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top