集册 Java实例教程 向SocketChannel写入

向SocketChannel写入

欢马劈雪     最近更新时间:2020-01-02 10:19:05

488
写入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);

    } 
展开阅读全文