无法查看控制台中打印的阵列的内容 [英] Cannot see the contents of the array printed in console

查看:104
本文介绍了无法查看控制台中打印的阵列的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public RMI post(PrintStream stream, Object object)
{
try
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    ObjectOutputStream oos = new ObjectOutputStream(baos);

    //

    oos.writeObject(System.rmi);

    oos.flush();

    oos.close();

    //

    stream.println("Class size: " + baos.toByteArray().length);

    stream.println("Class data: " + baos.toByteArray());

    stream.flush();

    stream.close();

    //
}
catch (Exception e)
{
    e.printStackTrace();
}

return this;

}

这将打印[B @ 12843fce,而不是预期的基础字节码结构.在FileOutputStream中可以找到相同的操作,但在ByteArrayOutputStream中不能找到.我们真的需要这个来工作.您能发现什么地方出了问题或发生了什么事吗?

This prints [B@12843fce instead of the expected underlying bytecode structure. The same operation works find with FileOutputStream but here not with ByteArrayOutputStream. We would really need this to work. Can you spot what's wrong or what's happened?

推荐答案

不要打印对该对象的引用,您需要一种将byte[]转换为String的正确方法,一种常见的方法是Arrays.toString(baos.toByteArray()).

Don't print the reference to the object, you need a proper way to translate the byte[] to a String, and a common way is Arrays.toString(baos.toByteArray()).

这篇关于无法查看控制台中打印的阵列的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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