On a PlayN http://code.google.com/p/playn/项目我有以下Java代码
import com.google.common.base.Charsets;
import java.nio.ByteBuffer;
ByteBuffer msg = ... // a ByteBuffer that contains a String
String s = Charsets.UTF_8.decode(msg).toString();
这在 Java 中工作得很好,但是当我尝试用 GWT 编译它时,我得到:
The method decode(ByteBuffer) is undefined for the type Charset
在 GWT 中,获取 ByteBuffer 内的字符串(以 UTF-8 编码)的正确方法是什么?
你应该能够使用new String(bytes, "UTF-8")
取出字节后ByteBuffer
as a byte[]
using ByteBuffer#get(byte[])
.
This String
构造函数,以及getBytes(String)
,针对 UTF-8 和 ISO-8859-1 实现。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)