java 低于 19 的较低 API 上的 StandardCharsets.UTF_8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32102166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
StandardCharsets.UTF_8 on lower API lower than 19
提问by EspeH
I'm using this code to get scandinavian characters posted to php correctly.
我正在使用此代码将斯堪的纳维亚字符正确发布到 php。
Issue here is that StandardCharsets.UTF_8 is not supported before API 19
这里的问题是在 API 19 之前不支持 StandardCharsets.UTF_8
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
DataOutputStream wr = new DataOutputStream( con.getOutputStream());
wr.write( postData );
Field requires API level 19 (Current min is 14): java.nio.charset.StandardCharsets#UTF_8
字段需要 API 级别 19(当前最小值为 14):java.nio.charset.StandardCharsets#UTF_8
How should I do this with API lower than 19?
我应该如何使用低于 19 的 API 执行此操作?
回答by Kirill Feoktistov
Use forNamestatic method of Charsetclass:
使用Charset类的forName静态方法:
byte[] postData = urlParameters.getBytes(Charset.forName("UTF-8"));
List of standard charsets you can find in documentation.
您可以在文档中找到的标准字符集列表。