Java IO Tutorial - Java CharsetEncoder .averageBytesPerChar ()








Syntax

CharsetEncoder.averageBytesPerChar() has the following syntax.

public final float averageBytesPerChar()

Example

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();

    System.out.println(encoder.averageBytesPerChar());
  }
}

The code above generates the following result.