The DataOutputStream class has a writeBoolean( ) method, and the DataInputStream class has a corresponding readBoolean( ) method:

public final void writeBoolean(boolean b) throws IOException
public final boolean readBoolean( ) throws IOException

Although theoretically a single bit could be used to indicate the value of a boolean, in practice a whole byte is used. This makes alignment much simpler and the extra space it uses isn't large enough to create an issue on modern machines. The writeBoolean( ) method writes a 0 byte (0x00) to indicate false or a 1 byte (0x01) to indicate true. The readBoolean( ) method interprets 0 as false and any positive number as true. Negative numbers indicate end of stream and lead to an EOFException being thrown.

Basic I/O

Introducing I/O

Output Streams

Input Streams

Data Sources

File Streams

Network Streams

Filter Streams

Filter Streams

Print Streams

Data Streams

Streams in Memory

Compressing Streams

JAR Archives

Cryptographic Streams

Object Serialization

New I/O



Nonblocking I/O

The File System

Working with Files

File Dialogs and Choosers


Character Sets and Unicode

Readers and Writers

Formatted I/O with java.text


The Java Communications API


The J2ME Generic Connection Framework


Character Sets

Java I/O
Java I/O
ISBN: 0596527500
EAN: 2147483647
Year: 2004
Pages: 244 © 2008-2020.
If you may any questions please contact us: