7 Years
Discussion Span
Last Post by JamesCherrill

DataOutputStream outputs data in its raw binary form - eg always 4 bytes for an int
PrintStream outputs data in a human-readable character format - so an int could be anything such as "0" or "-1234567"


Thanks. Does that mean that if we write the integer 2 using DataOutputStream, it'll write 0x0002, whereas if we use PrintStream, it'll convert it into the unicode code 0x32 and then use the UTF-8 or whatever is the default encoding of the platform to write that to the file ? Am i right ?


The differences between the two classes are twofold: a DataOutputStream will write numeric data in a binary format, while the PrintStream will provide a human readable form. The methods of a DataOutputStream will throw exceptions, while for the PrintStream I/O errors are treated internally and can only be accessed with a special method checkErrors(). This is why in the standard phrase System.out.println you do not have to care about exceptions

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.