Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display a byte array as a char array in the Eclipse Java debugger?

I want to view a byte array in the Eclipse (Helios Release, build id: 20100617-1415) Java debugger as a char array? Is that possible? How?

For example, I want to display this:

alt text

...as: '\0', '0', 'G', '\22', etc.

like image 776
Daryl Spitzer Avatar asked Feb 16 '26 11:02

Daryl Spitzer


1 Answers

  1. Set a breakpoint after the byte array.
  2. Select the byte array and click watch. It will appear in the Expressions view.
  3. Click on the expression, mine is called aBytes, and click edit Watch Expressions.
  4. Enter the following expression:


new String(aBytes).toCharArray();

Caveat - it will use the system dependent encoding - which may well screw up your output if it's not in the encoding you think it is. If you know the encoding you can use:

new String(aBytes, java.nio.charset.Charset.forName("UTF-8")).toCharArray();
like image 174
Jon Avatar answered Feb 17 '26 23:02

Jon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!