How do I convert between ByteBuffer and a CharBuffer using Java 1.4?

John Zukowski

The java.nio.charset package include character set converters for you. To go from ByteBuffer to CharBuffer, you would do something like the following:

ByteBuffer buffer = ...
Charset charset = Charset.forName("ISO-8859-1");
CharsetDecoder decoder = charset.newDecoder();
CharBuffer charBuffer = decoder.decode(buffer);
For different character sets, provide a different name to the forName() call.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact