Skip to Main Content
Java I/O, 2nd Edition
book

Java I/O, 2nd Edition

by Elliotte Rusty Harold
May 2006
Beginner to intermediate content levelBeginner to intermediate
726 pages
19h 57m
English
O'Reilly Media, Inc.
Content preview from Java I/O, 2nd Edition

Chapter 8. Data Streams

Data streams read and write strings, integers, floating-point numbers, and other data that’s commonly presented at a higher level than mere bytes. The java.io.DataInputStream and java.io.DataOutputStream classes read and write the primitive Java data types (boolean, int, double, etc.) and strings in a particular, well-defined, platform-independent format. Since DataInputStream and DataOutputStream use the same formats, they’re complementary. What a data output stream writes, a data input stream can read and vice versa. These classes are especially useful when you need to move data between platforms that may use different native formats for integers or floating-point numbers.

The Data Stream Classes

The java.io.DataInputStream and java.io.DataOutputStream classes are subclasses of FilterInputStream and FilterOutputStream, respectively.

public class DataInputStream extends FilterInputStream implements DataInput
public class DataOutputStream extends FilterOutputStream
                              implements DataOutput

They have all the usual methods you expect in input and output stream classes, such as read( ), write( ), flush( ), available( ), skip( ), close( ), markSupported( ), and reset( ). (Data input streams support marking if, and only if, their underlying input stream supports marking.) However, the real purpose of DataInputStream and DataOutputStream is not to read and write raw bytes using the standard input and output stream methods. It’s to read and interpret multibyte data like ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java I/O

Java I/O

Elliotte Rusty Harold
Java NIO

Java NIO

Ron Hitchens

Publisher Resources

ISBN: 0596527500Errata PageSupplemental Content