public String decode(ByteBuffer buffer){ //解码 CharBuffer charBuffer= charset.decode(buffer); return charBuffer.toString(); } public ByteBuffer encode(String str){ //编码 return charset.encode(str); }
public static void main(String args[])throws Exception{ final EchoServer server = new EchoServer(); Thread accept=new Thread(){ public void run(){ server.accept(); } }; accept.start(); server.service(); } }