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

六眼飞鱼酱① 提交于 2020-02-24 05:54:26

问题


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:

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


回答1:


  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();



回答2:


View a String as a String? Too hard. You have to do this:

new String(aBytes).toString();

...if you try this:

new String(aBytes); 

...you only get "null". ARGH. This with Luna, all latest as of this date.



来源:https://stackoverflow.com/questions/3919941/how-do-i-display-a-byte-array-as-a-char-array-in-the-eclipse-java-debugger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!