DataInputStream readUnsignedByte() method in Java with Examples Last Updated : 05 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The readUnsignedByte() method of DataInputStream class in Java is used to read byte and returns as an integer. The integer is an unsigned value in the range from 0 to 255. The bytes in this method are read from the accommodated input stream. Syntax: public final int readUnsignedByte() throws IOException Specified By: This method is specified by readUnsignedByte() method of DataInput interface. Parameters: This method does not accept any parameter. Return value: This method returns the byte value read as an integer. It is an unsigned 8-bit byte. Exceptions: EOFException - It throws EOFException if the input stream is ended. IOException - This method throws IOException if the stream is closed or some other I/O error occurs. Below programs illustrate readUnsignedByte() method in DataInputStream class in IO package: Program 1: Java // Java program to illustrate // DataInputStream readUnsignedByte() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Create byte array byte[] b = { 10, 20, 30, 40, 50 }; // Create byte array input stream ByteArrayInputStream byteArrayInputStr = new ByteArrayInputStream(b); // Convert byte array input stream to // DataInputStream DataInputStream dataInputStr = new DataInputStream( byteArrayInputStr); while (dataInputStr.available() > 0) { // Print bytes System.out.println( dataInputStr.readUnsignedByte()); } } } Output: 10 20 30 40 50 Program 2: Java // Java program to illustrate // DataInputStream readUnsignedByte() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Create byte array byte[] b = { -20, -10, 0, 10, 20 }; // Create byte array input stream ByteArrayInputStream byteArrayInputStr = new ByteArrayInputStream(b); // Convert byte array input stream to // DataInputStream DataInputStream dataInputStr = new DataInputStream( byteArrayInputStr); while (dataInputStr.available() > 0) { // Print bytes System.out.println( dataInputStr.readUnsignedByte()); } } } Output: 236 246 0 10 20 References: https://docs.oracle.com/javase/10/docs/api/java/io/DataInputStream.html#readUnsignedByte() Comment More infoAdvertise with us Next Article DataInputStream read() method in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-IO package Practice Tags : Java Similar Reads DataInputStream readUnsignedShort() method in Java with Examples The readUnsignedShort() method of DataInputStream class in Java is used to read two input bytes and returns an integer value. This method reads the next two bytes from the input stream and interprets it into integer type and returns. Syntax: public final int readUnsignedShort() throws IOException Sp 2 min read DataInputStream readByte() method in Java with Examples The readByte() method of DataInputStream class in Java is used to read and return one input byte. The byte is a signed value in the range from -128 to +127. The bytes in this method are read from the accommodated input stream. Syntax: public final byte readByte() throws IOException Specified By: Thi 2 min read DataInputStream readInt() method in Java with Examples The readInt() method of DataInputStream class in Java is used to read four input bytes and returns a integer value. This method reads the next four bytes from the input stream and interprets it into integer type and returns. Syntax: public final int readInt() throws IOException Specified By: This me 2 min read DataInputStream readDouble() method in Java with Examples The readDouble() method of DataInputStream class in Java is used to read eight input bytes and returns a double value. This method reads the next eight bytes from the input stream and interprets it into double type and returns. Syntax: public final double readDouble() throws IOException Specified By 2 min read DataInputStream read() method in Java with Examples The read() method of DataInputStream class in Java is of two types: read(byte[] b) method of DataInputStream class in Java is used to read bytes from the input stream and store them into the buffer byte array.This read() method returns the number of bytes actually read as an integer type. This metho 4 min read DataInputStream readFully() method in Java with Examples The readFully() method of DataInputStream class in Java is of two types: readFully(byte[] b) method of DataInputStream class in Java is used to read bytes equal to the length of byte array b from an input stream and store them into the byte array b. General Contract: The readFully(byte[] b) method i 4 min read Like