InputStream
is an abstract class used to read byte-oriented data from input sources such as files, memory or network connections.
java.io
package.
read()
to read data from input sources.
FileInputStream fis = new FileInputStream("file.txt");
int data = fis.read();
fis.close();
FileInputStream fis = new FileInputStream("file.txt");
int data = fis.read();
fis.close();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("file.txt"));
int b = bis.read();
DataInputStream dis = new DataInputStream(new FileInputStream("data.bin"));
int num = dis.readInt();
PushbackInputStream pbis = new PushbackInputStream(new FileInputStream("file.txt"));
int b = pbis.read();
pbis.unread(b);
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("object.ser"));
MyClass obj = (MyClass) ois.readObject();
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pis);
pos.write(65);
int b = pis.read(); // reads 'A'
SequenceInputStream sis = new SequenceInputStream(
new FileInputStream("a.txt"),
new FileInputStream("b.txt")
);
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weโre here to make our tutorials better based on your thoughts and suggestions.