Java examples for java.nio.channels:SocketChannel
send string to SocketChannel
//package com.java2s; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Main { /**/*from www .j ava 2 s . co m*/ * send str * * @param channel * @param str * @throws Exception */ public static void write(SocketChannel channel, String str) throws Exception { channel.write(ByteBuffer.wrap(str.getBytes())); } /** * send str * * @param channel * @param contents * @throws Exception */ public static void write(SocketChannel channel, byte[] contents) throws Exception { channel.write(ByteBuffer.wrap(contents)); } }