Java IO Tutorial - Java CharsetEncoder .flush (ByteBuffer out)








Syntax

CharsetEncoder.flush(ByteBuffer out) has the following syntax.

public final CoderResult flush(ByteBuffer out)

Example

In the following code shows how to use CharsetEncoder.flush(ByteBuffer out) method.

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
//from ww w. j ava  2  s.co  m
public class Main {
  public static void main(String[] args) throws Exception{
    CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();

    String response = "java2s.com";
    
    ByteBuffer bb = ByteBuffer.allocate(10);
    
    System.out.println(encoder.flush(bb));
  }
}

The code above generates the following result.