generally i see that BufferedOutputStream objects are wrapped with DataOutputStream, what is the reason for this design?
why do coders prefer this style instead of doing operations on
BufferedOutputStream objects.
i am newbie to java, i will appreciate if the explanation is clear enough for a beginner to understand
e.g:
- DataOutputStream out2 =
-
new DataOutputStream(
-
new BufferedOutputStream(new FileOutputStream("Data.txt"))
-
);
A DataOutputStream can write ints, longs and other primitive data types.
A BufferedOutputStream can just buffer a bunch of bytes. One stream can do
things the other can't and vice versa. Wrapping them (in the correct order) offers
you all the functionality, i.e. you can write ints, longs and other primitive data
types to a buffered stream.
Also read the article in the Java Articles section about Decorators.
kind regards,
Jos