Java I/O Tutorial
Java I/O (Input and Output) is used to process the input and produce the output.
Java uses the concept of a stream to make I/O operation fast. The java.io package contains all the classes required for input and output operations.
We can perform file handling in Java by Java I/O API.
A stream is a sequence of data. In Java, a stream is composed of bytes. It's called a stream because it is like a stream of water that continues to flow.
In Java, 3 streams are created for us automatically. All these streams are attached with the console.
1) System.out: standard output stream
2) System.in: standard input stream
3) System.err: standard error stream
Let's see the code to print output and an error message to the console.
Let's see the code to get input from console.
OutputStream vs InputStream
The explanation of OutputStream and InputStream classes are given below:
Java application uses an output stream to write data to a destination; it may be a file, an array, peripheral device or socket.
Java application uses an input stream to read data from a source; it may be a file, an array, peripheral device or socket.
Let's understand the working of Java OutputStream and InputStream by the figure given below.
OutputStream class is an abstract class. It is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink.
Useful methods of OutputStream
InputStream class is an abstract class. It is the superclass of all classes representing an input stream of bytes.
Useful methods of InputStream
Next TopicJava FileOutputStream class