eclipse 如何在java的调试详细信息格式化程序中将字节数组显示为字符串?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/381546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:27:17  来源:igfitidea点击:

How can I display a byte array as a String in java's debug detail formatter?

javaeclipsedebugging

提问by Chris R

I'd like to write a simple detail formatter that displays byte[]data in the form of a String(using String.<init>([B)to do the dirty work).

我想编写一个简单的细节格式化程序,byte[]以 a 的形式显示数据StringString.<init>([B)用于做脏活)。

However, I'm not sure how to find the class name for [Bto use when creating the formatter. Is this even possible? Or, alternatively, is there another way to view byte arrays as strings in the debugger?

但是,我不确定如何找到[B在创建格式化程序时使用的类名。这甚至可能吗?或者,是否有另一种方法可以在调试器中将字节数组视为字符串?

回答by Jason Day

I don't know how to get eclipse's detail formatter to automagically display byte arrays as Strings, but you can display a particular byte array by adding new String(byteArray)as a watch expression.

我不知道如何让 eclipse 的详细信息格式化程序自动将字节数组显示为字符串,但是您可以通过添加new String(byteArray)为监视表达式来显示特定的字节数组。

回答by whaley

If your question is how would I get a string representation of a byte array of [0,1,2] to be "[0,1,2]", I would suggest you take a look at Arrays.toString(byte[])

如果您的问题是如何将 [0,1,2] 的字节数组的字符串表示形式变为“[0,1,2]”,我建议您查看 Arrays.toString(byte[] )

http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#toString(byte[])

http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#toString(byte[])

回答by Thorsten

You can't add Detail Formatters for simple Datatypes like byte.

您不能为简单的数据类型(如byte.

回答by Nathaniel Flath

The [B type can be retrieved with byte[].class.

[B 类型可以用 byte[].class 检索。

回答by Michael Borgwardt

byte[].class