Java IO Tutorial - Java CharsetEncoder .averageBytesPerChar ()


CharsetEncoder.averageBytesPerChar() has the following syntax.

public final float averageBytesPerChar()


In the following code shows how to use CharsetEncoder.averageBytesPerChar() method.

/* w w  w. j  a v a  2  s  .  c  o  m*/
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

public class Main {
  public static void main(String[] args) throws Exception{
    CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();


The code above generates the following result.