Java CharsetDecoder .decode (ByteBuffer in)

Syntax

CharsetDecoder.decode(ByteBuffer in) has the following syntax.

public final CharBuffer decode(ByteBuffer in)   throws CharacterCodingException

Example

In the following code shows how to use CharsetDecoder.decode(ByteBuffer in) method.


import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
//from  ww w.  j  a  v  a 2s.c o  m
public class Main {
  public static void main(String[] argv) throws Exception {
    Charset charset = Charset.forName("ISO-8859-1");
    CharsetDecoder decoder = charset.newDecoder();
    CharsetEncoder encoder = charset.newEncoder();

    ByteBuffer bbuf = encoder.encode(CharBuffer.wrap("a string"));

    CharBuffer cbuf = decoder.decode(bbuf);
    String s = cbuf.toString();
  }
}




















Home »
  Java Tutorial »
    java.nio.charset »




Charset
CharsetDecoder
CharsetEncoder
StandardCharsets