如何在Eclipse Java调试器中将字节数组显示为char数组? [英] How do I display a byte array as a char array in the Eclipse Java debugger?

查看:125
本文介绍了如何在Eclipse Java调试器中将字节数组显示为char数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Eclipse中查看一个字节数组(Helios Release,build id:20100617-1415)Java调试器作为一个char数组?那可能吗?如何?



例如,我想显示:





... as:'\0','0',' G','\22'等。

解决方案


  1. 设置字节数组后的断点。

  2. 选择字节数组并单击watch。它将出现在表达式视图中。

  3. 点击表达式,我的名字叫做B字母,然后点击编辑Watch表达式。

  4. 输入以下表达式:


  new String(aBytes).toCharArray(); 

警告 - 它将使用依赖于系统的编码 - 如果它不在你认为的编码。如果您知道可以使用的编码:

  new String(aBytes,java.nio.charset.Charset.forName(UTF -8))。toCharArray(); 


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

这篇关于如何在Eclipse Java调试器中将字节数组显示为char数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆