Java DataInputStream Class
In Java language, DataInputStream is used to read primitives data from the input stream.
In generally java application uses the data output stream to write data and it read the data input stream. It reads the data instead of just bytes.
Syntax:
public class DataInputStream extends FilterInputStream implements DataInput
To create an InputStream
InputStream in = new DataInputStream(InputStream in);
DataInputStream Class Methods
| S.No | Method | Description |
|---|---|---|
| 1 | Public final int read(byte [] a) | This method is used to read the number of bytes from the input stream. |
| 2 | public final int read(byte[] a, int off, int len) | This method is used to read len bytes of data from the input stream. |
| 3 | public final boolean readBoolean() | This method is used to read input byte and return true when byte is non zero otherwise return false. |
| 4 | public final byte readByte() | This method is used to read and return the one input byte. |
| 5 | public String readLine() | This method is used to reads some bytes from the inputstream an stores in to the byte array. |
| 6 | public final int readInt() | This method is used to read input bytes and return an int value. |
Example:
import java.io.*;
public class DataInputStreamDemo{
public static void main(String args[]) throws IOException{
DataInputStream datain = new DataInputStream(new FileInputStream("F:\\out.txt"));
int c= datain.available();
byte[] arr = new byte[c];
inst.read(arr);
for (byte b : arr) {
char i = (char) b;
System.out.print(i+" ");
}
}
}
Output
S u c c e s s
out.txt
Success
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com