2 Examples to Convert Byte[] array to String in Java
Things to remember and Best Practices
Always remember, using character encoding while converting byte array to String is not a best practice but mandatory thing. You should always use it irrespective of programming language. By the way, you can take note of following things, which will help you to avoid couple of nasty issues :- Use character encoding from the source e.g. Content-Type in HTML files, or <?xml encoding="…">.
- Use XML parsers to parse XML files instead of finding character encoding and reading it via InputStream, some things are best left for demo code only.
- Prefer Charset constants e.g. StandardCharsets.UTF_16 instead of String "UTF-16"
- Never rely on platform's default encoding scheme
Read full article from 2 Examples to Convert Byte[] array to String in Java
No comments:
Post a Comment