This module introduces developers to how to use streams to read data in Java.
In addition, you will learn how to use various methods to make using input streams more efficient.
In this module, you will learn the following:
How to efficiently read data from a stream
How to use the available() method to count available bytes in a stream
How to skip unnecessary data
When to close streams
In this module, all data will be raw bytes. Later modules will show you how to read and write data without explicitly converting it to and from bytes first.
The java.io.InputStream class is the abstract superclass for all input streams
It declares the three basic methods needed to read bytes of data from a stream.
It also has methods for
- closing and flushing streams,
- checking how many bytes of data are available to be read,
- skipping over input,
- marking a position in a stream and resetting back to that position, and
- determining whether marking and resetting are supported.
public abstract int read() throws IOException
public int read(byte data) throws IOException
public int read(byte data, int offset, int length) throws IOException
public long skip(long n) throws IOException
public int available() throws IOException
public void close() throws IOException
public synchronized void mark(int readlimit)
public synchronized void reset() throws IOException
public boolean markSupported()