Open In App

Java.io.DataInputStream class in Java | Set 2

Last Updated : 11 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report
Java.io.DataInputStream class in Java | Set 1 More Methods:
  • byte readByte() : Reads and returns one input byte.
    Syntax:public final byte readByte()
                        throws IOException
    Returns: the next byte of this input stream as a signed 8-bit byte.
    Throws:
    EOFException
    IOException 
    
  • float readFloat() : Reads four input bytes and returns a float value.
    Syntax:public final float readFloat()
                          throws IOException
    Returns :the next four bytes of this input stream, interpreted as a float.
    Throws:
    EOFException 
    IOException
  • void readFully(byte[] b) : Reads some bytes from an input stream and stores them into the buffer array b.
    Syntax:public final void readFully(byte[] b)
                         throws IOException
    Parameters:
    b - the buffer into which the data is read.
    Throws:
    EOFException
    IOException
  • void readFully(byte[] b, int off, int len) : Reads len bytes from an input stream.
    Syntax:public final void readFully(byte[] b,
                 int off,
                 int len)
                         throws IOException
    Parameters:
    b - the buffer into which the data is read.
    off - the start offset of the data.
    len - the number of bytes to read.
    Throws:
    EOFException 
    IOException
  • String readLine() : Reads the next line of text from the input stream.
    Syntax:
    Returns: the next line of text from this input stream.
    Throws:
    IOException
    Deprecated This method does not properly convert bytes to characters.
    
  • long readLong() : Reads eight input bytes and returns a long value.
    Syntax:public final long readLong()
                        throws IOException
    Returns:
    the next eight bytes of this input stream, interpreted as a long.
    Throws:
    EOFException
    IOException
  • short readShort() : Reads two input bytes and returns a short value.
    Syntax:public final short readShort()
                          throws IOException
    Returns:
    the next two bytes of this input stream, interpreted as a signed 16-bit number.
    Throws:
    EOFException
    IOException
  • String readUTF() : Reads  a string that has been encoded using a modified UTF-8 format.
    Syntax:public final String readUTF()
                         throws IOException
    Returns:
    a Unicode string.
    Throws:
    EOFException 
    IOException
    UTFDataFormatException 
    
  • int skipBytes(int n) : Makes an attempt to skip over n bytes of data from the input stream, discarding the skipped bytes.
    Syntax:public final int skipBytes(int n)
                        throws IOException
    Parameters:
    n - the number of bytes to be skipped.
    Returns:
    the actual number of bytes skipped.
    Throws:
    IOException
Program 2:
Output:
Values: 49  4.4545 geeksforgeeks  GeeksforGeeks 
[67, 68, 69, 70]

Next Article
Article Tags :
Practice Tags :

Similar Reads