0

What is the difference between DataOutputStream and printwriter?

hichris123
  • 10,145
  • 15
  • 56
  • 70
Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56

2 Answers2

2

A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in.

PrintWriter prints formatted representations of objects to a text-output stream.This class implements all of the print methods found in PrintStream. It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams. Unlike the PrintStream class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, rather than whenever a newline character happens to be output. These methods use the platform's own notion of line separator rather than the newline character.

Srinivas B
  • 1,821
  • 4
  • 17
  • 35
  • I am not sure about DataOutputStream output portability. Data written with DataOutputStream are designed to be read with DataInputStream. Eg String may be written in Java specific "modified UTF-8 format" – Evgeniy Dorofeev Nov 22 '12 at 04:34
  • @EvgeniyDorofeev That's the only case. All the other cases use network byte order, which is as portable as you can get. – user207421 Feb 10 '14 at 20:03
0

**Writer and Reader classes deal with textual characters (type char) and do some translation between Unicode and the real platform's file encoding.

DataOutputStream (Stream) classes deal in binary data (type byte), and do no such translation.**

Abdul
  • 942
  • 2
  • 14
  • 32