bytes in 'str = new String(bytes, “UTF8”) ' and 'bytes = str.getBytes(“UTF8”)' not the same value

旧街凉风 提交于 2019-11-30 16:45:44

When you decode a string as UTF-8 it is because you encoded the bytes as UTF-8 or something compatible. You can't just take a byte[] of random bytes and turn it into a String because it is binary data not text.

What you can do is use a Base64 encoder for the binary and a Base64 decoder to turn it back into the original bytes.

A hacky way of doing this is to use ISO-8859-1, but this is a bad idea generally as you are confusing binary and text data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!