Search code examples
javasocketchannel

how to write char array to java socketchannel


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


Solution

  • Have you tried using putChar method of ByteBuffer?

    ByteBuffer buf = ByteBuffer.allocate(1024);
    
    for (char ch : myChars) {
      buf.putChar(ch);
    }