How to convert an input stream to a Java object

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(reg_be);
oos.flush();
oos.close();

InputStream is = new ByteArrayInputStream(baos.toByteArray());

This code converts Java object to InputStream. How to convert InputStream to object? I need to convert my object to InputStream, and then I pass it. I want my object back

Solution

In the try block, you should write:

ObjectInputStream ois = new ObjectInputStream(is);
Object object = ois.readObject();

Objectinputstream is initialized with another stream, such as bufferedinputstream or your input stream is

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>