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 convert Java Object to InputStream and how can I convert InputStream to an Object?  I need to convert my Object to an InputStream then I pass it and I want to get my Object back.
To convert an InputStream Object int to a String using this method. Instantiate the Scanner class by passing your InputStream object as parameter. Read each line from this Scanner using the nextLine() method and append it to a StringBuffer object. Finally convert the StringBuffer to String using the toString() method.
Using nio packages exposed by Java 8, you can write an InputStream to a File using Files. copy() utility method.
In try block you should write:
ObjectInputStream ois = new ObjectInputStream(is);
Object object = ois.readObject();
ObjectInputStream is initialized with another stream, e.g. BufferedInputStream or your input stream is.
ObjectInputStream ois = new ObjectInputStream(is);
Object object = ois.readObject();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With