Here you can find the source of writeStringToSocketChannel(String text, SocketChannel sc)
public static void writeStringToSocketChannel(String text, SocketChannel sc)
//package com.java2s; //License from project: Apache License import java.nio.*; import java.nio.channels.*; import java.nio.charset.*; public class Main { private static Charset charset = Charset.forName("ISO-8859-2"); public static void writeStringToSocketChannel(String text, SocketChannel sc) { text += "\n"; try {//from w w w .j a va 2s.c o m ByteBuffer buf = charset.encode(text); while (buf.hasRemaining()) { sc.write(buf); } } catch (Exception ex) { ex.printStackTrace(); } } }