Code example for Charset

Methods: newDecoder

0
public class FileUtils 
{ 
 
    private static Charset charset = Charset.forName( "UTF-8" );
 
    private static CharsetDecoder decoder = charset.newDecoder();
 
    public static String fileRead( File file )
        throws IOException 
    { 
        FileInputStream is = null;
        try 
        { 
            is = new FileInputStream( file );
            FileChannel ch = is.getChannel();
            MappedByteBuffer mb = ch.map( MapMode.READ_ONLY, 0L, ch.size() );
            CharBuffer charBuffer = decoder.decode( mb );
            return charBuffer.toString();
        } 
        finally 
        {