Is the encoding name UTF8 or UTF-8?

Viewed 29003

Some httpclient requires me to give a string charsetµ.

I am wondering whether to give it UTF8 or utf8 or UTF-8?

Especially when calling Charset.forName(enc)

5 Answers

The standard name is 'UTF-8'. Source code(I use jdk1.8.0_20) showes more detail:

UTF_8 extends Unicode {
    public UTF_8() {
        super("UTF-8", StandardCharsets.aliases_UTF_8); // show other aliases
        // static final String[] aliases_UTF_8 = new String[]{"UTF8", "unicode-1-1-utf-8"};
    }

    public String historicalName() {
        // return old name of UTF-8
        return "UTF8";
    }
Charset charset = Charset.forName("cp1254"); 

This was the utf-8 solution for me. You can use it.

Related