JDK (Java Development Kit) Tutorials
Dr. Herong Yang, Version 5.00

Charset.decode() - Method to Decode Byte Sequences

This section provides a tutorial example on how to decode byte sequences back to characters with a given encoding using different decoding methods provided by JDK: CharsetDecoder.decode(), Charset.decode(), new String(), InputStreamReader.read()

There are 4 methods provided by JDK to decode byte sequences back to characters:

  • CharsetDecoder.decode()
  • Charset.decode()
  • new String()
  • InputStreamReader.read()

Ways to use those decode methods are similar to encode methods.

Exercise: Write a sample program to decode byte sequences similar to the encode sample program, EncodingSampler.java.

Last update: 2006.

Sections in This Chapter

What Is Character Encoding?

Supported Character Encodings in JDK

Charset.encode() - Method to Encode Characters

Running EncodingSampler.java with CP1252 Encoding

Running EncodingSampler.java with ISO-8859-1 and US-ASCII

Running EncodingSampler.java with UTF-8, UTF-16, UTF16-BE

Running EncodingSampler.java with GB18030

Charset.decode() - Method to Decode Byte Sequences

Dr. Herong Yang, updated in 2008
Charset.decode() - Method to Decode Byte Sequences