2

I am using a JavaScript to Applet object called JSObject and I get from my JSObject the value of a java object that I stored in my html page.

The java object is a byte[] but JavaScript converts it to a String.

So in the HTML page: object value = [B@ca0b6

In the Applet, the String value is also [B@ca0b6

Is there a way for me to convert this String value of [B@ca0b6 into the byte representation? I don't mean String.getByte() because that will convert the STRING [B@ca0b6 into byte[] data.

Thanks!

Castiblanco
1,1984 gold badges13 silver badges33 bronze badges
asked Dec 30, 2010 at 20:19
2
  • There are no objects in HTML. Do you mean the object you saved in JS? Commented Dec 30, 2010 at 20:21
  • Yes, I've updated this answer to something more understandable: stackoverflow.com/questions/4566346/… Commented Dec 30, 2010 at 21:19

2 Answers 2

3

No, you can't. This is the default toString() method, which does not output anything of the array contents. It contains only the type of the object (array of bytes) and the memory address within the JVM, in hex.

If you want to convert your array to String properly, use Arrays.toString(array)

answered Dec 30, 2010 at 20:21

2 Comments

Interesting, I'll need to find a different approach. Thanks!
I've created a new question to try to solve this approach: stackoverflow.com/questions/4566346/… Thanks!
1

You can use:

new String(bytearray, "UTF-8")

(change UTF-8 to something else (e.g., ISO-8859-1) if your bytes are not UTF-8.)

answered Dec 30, 2010 at 20:23

3 Comments

I think he doesn't want this.
@Bozho: It's too bad the question isn't more explicit in what the OP wants. :-( Both your answer and mine are correct, depending on how the question is interpreted.
I assumed the "string" interferes not because it consists of the bytes, but because it is outputted as a string in html

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.