Java IO Tutorial - Java Charset.forName(String charsetName)








Syntax

Charset.forName(String charsetName) has the following syntax.

public static Charset forName(String charsetName)

Example

In the following code shows how to use Charset.forName(String charsetName) method.

// w w  w .j a v  a2 s. c  o m
import java.nio.charset.Charset;

public class Main {

  public static void main(String[] args) {
    
      Charset cs = Charset.forName("US-ASCII");
      System.out.println(cs.displayName());
      System.out.println(cs.toString());

  }
}

The code above generates the following result.