写入SocketChannel
import java.io.IOException;/** n o w j a v a . c o m 提 供 **/ import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Main { public static void main(String[] args) { ByteBuffer buf = ByteBuffer.allocateDirect(1024); try { buf.put((byte) 0xFF); // Prepare the buffer for reading by the socket buf.flip(); SocketChannel socketChannel = null; // Write bytes int numBytesWritten = socketChannel.write(buf); }