【发布时间】:2019-04-26 10:05:11
【问题描述】:
我创建了一个 ObjectOutputStream
ObjectOutputStream stream = new ObjectOutputStream(new ByteArrayOutputStream());
stream.writeObject(myObject);
但是我现在如何将它转换回Object,甚至是ByteArray?
我尝试过获取这样的 ObjectInputStream
ByteArrayOutputStream outputStream = (ByteArrayOutputStream) myProcess.getOutputStream();
final ObjectInputStream objectInputStream = new ObjectInputStream(
new ByteArrayInputStream(outputStream.toByteArray()));
但是我得到一个编译错误,说它不能将 ObjectOutputStream 转换为 ByteArrayOutputStream;但是ObjectOutputStream 上似乎没有方法可以取回数据?
【问题讨论】:
标签: java stream outputstream bytearrayoutputstream