开发者

Convert a stream of bytes to a String (UTF-8 encoded)

I have a stream of bytes (given by a BufferedInputStream) which represents a sequence of UTF-8 strings. The protocol is a little crappy becauses it uses 0xFF between commands, which implies that the whole stream is not a valid UTF-8 string, only the parts between the 0xFF are.

How can I extract those UTF-8 strings.

I don’t think BufferedReader would work, because the 0xFF will mess 开发者_C百科up everything and I have found no byte array to UTF-8 string conversion function.


byte[] to String

So would be new String(bytes, "UTF-8");

You would need to filter the Stream beforehand though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜