ANSWERS: 3
  • You can pass in the byte array and character set into the String constructor, then call getBytes("UTF-8") on the resultant String - you now have an array of UTF-8 encoded bytes.
  • Thanks .... Can you please provide example code? Your answer would appear to be lacking necessary information. In fact, your answer looks like you are trying to convert between some character set encoded as bytes and UTF-8 instead of bytes and UTF-8. In my case there is no source character set. These aren't characters. These are bytes I wish to transform into UTF-8. Does Java/UTF-8 provide no recognized way to convert bytes into UTF-8 characters?
  • To convert UTF-8 bytes into a string, use new String(bytearray, "utf-8"). To reverse that, use mystring.getBytes("utf-8")

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy