Java IO Tutorial - Java Charset.newEncoder()








Syntax

Charset.newEncoder() has the following syntax.

public abstract CharsetEncoder newEncoder()

Example

In the following code shows how to use Charset.newEncoder() method.

import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
//from w  w  w . j av  a 2s. co m
public class Main {

  public static void main(String[] args) {
    Charset inCharset = Charset.forName("UTF8");
    Charset outCharset = Charset.forName("UTF16");

    CharsetDecoder inDecoder = inCharset.newDecoder();
    CharsetEncoder outEncoder = outCharset.newEncoder();

  }
}