DataInputStream readByte() in Java

readByte(): This method is available in the java.io.DataInputStream class of Java.

Syntax:

byte java.io.DataInputStream.readByte() throws IOException

This method sees the general contract of the readBytemethod of DataInput. Bytes for this operation are read from the contained input stream.

Parameters: NA

Returns: the next byte of this input stream as a signed 8-bit byte.

Throws:

1. EOFException - if this input stream has reached the end.

2. IOException - the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.

Approach

Java

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class DataInputStreamreadByte {
    public static void main(String[] args) throws IOException {

        InputStream in = new FileInputStream("hello.txt");
        DataInputStream dataInputStream =
new DataInputStream(in);

        System.out.println(dataInputStream.readByte());

        dataInputStream.close();
    }
}

Output:

67


No comments:

Post a Comment