Java I/O Data Streams

Advertisement

In this tutorial we will discuss the Java I/O Data Streams.

Java I/O Data Streams

In this tutorial we will discuss the Java I/O Data Streams.

To deal with the binary I/O of primitive data type values as well as the
String values Java provided the support of Data stream. DataInput or the
DataOutput is the interface which is implemented by all the data streams classes.

DataInput : An interface that facilitate to read byte from
the binary stream and rebuild that data into any of the Java primitive types
along with this facility a String from data in the UTF-8 format can also be
rebuild.

There are several classes that implements the DataInput interface. Some of them are as follows :

This class provides the facility to read and write to a random access
file.

ObjectOutputStream

This class is used to write the primitive data types and
graphs of Java objects into an output stream.

Methods of DataOutput

write(byte[] b) : This method is used to write all the
bytes of a specified array (say, b is an array) into the output stream.

void write(byte[] b) throws IOException

write(byte[] b, int off, int len) :
This method is used to write the specified number of bytes from the specified
array into the output stream.

void write(byte[] b, int off, int len) throws IOException

write(int b) : This method is used to write for the
integer argument to the output stream.

void write(int b) throws IOException

writeBoolean(boolean v) :

void writeBoolean(boolean v) throws IOException

writeByte(int v) : This method is used to write for the
integer argument to the output stream but the written byte using this method can
be read by readByte() method of DataInput.void writeByte(int v) throws IOException

writeBytes(String s) : This method is used to write
string, in order to one byte, into the output stream.

void writeBytes(String s) throws IOException

writeChar(int v) : This method is used to write the char
value that made up from the two bytes, into the output stream.

void writeChar(int v) throws IOException

writeChars(String s) : This method is used to write each
characters of a specified string in order to two bytes per character, into the
output stream.

void writeChars(String s) throws IOException

writeDouble(double v) : This method is used to write the
double value that made up from the eight bytes into the output stream.

void writeDouble(double v) throws IOException

writeFloat(float v) : This method is used to write the
float value that made up from the four bytes into the output stream.

void writeFloat(float v) throws IOException

writeInt(int v) : This method is used to write the int
value that made up from the four bytes into the output stream.

void writeInt(int v) throws IOException

writeLong(long v) : This method is used to write the long
value that made up from the eight bytes into the output stream.

void writeLong(long v) throws IOException

writeShort(int v) : This method is used to write the two
bytes into the output stream for displaying the argument's value

void writeShort(int v) throws IOException

writeUTF(String s) : This method is used to write the
string s into the output stream.