Can I use a BufferedOutputStream with an ObjectOutputStream to serialize an object?
Here's an example of how to do this:
... String myobject = new String("myobject"); FileOutputStream file = new FileOutputStream("myobject.ser"); BufferedOutputStream bout = new BufferedOutputStream(file); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(myobject); out.flush(); ...
Java allows you to chain I/O streams together. Using a BufferedOutputStream makes output much more efficient because the I/O overhead is then expended on large chunks of data, rather than on individual bytes.