views:

57

answers:

1

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.

+7  A: 
  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();
Jon
and if the array is very large, it will kill your debug.
tulskiy
Luckily I only need to do this for arrays of modest length.
Daryl Spitzer