See the comments in the code below for an explanation:
//Create a Java string
var example = new java.lang.String('This is plain text');
//Convert String to bytes. This method is only available on Java strings. Not JavaScript strings.
var bytes = example.getBytes();
qie.debug("Output plain text: " + example);
qie.debug("Output as bytes: " + bytes);
//Try to convert bytes to string. This does not convert it back to the original text.
qie.debug("Output result of calling toString() on bytes: " + bytes.toString());
//Convert bytes to string. This is the correct way to convert the byte[] to the original text.
var s = new java.lang.String(bytes);
qie.debug("Output converting bytes back to text : " + s);
Here are the results of executing the above code:
Output plain text: This is plain text
Output as bytes: [B@68a394
Output result of calling toString() on bytes: [B@68a394
Output converting bytes back to text : This is plain text