Java.io.DataInputStream class in Java | Set 2 Last Updated : 23 Jul, 2025 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: Java //Java program to demonstrate DataInputStream // This program uses try-with-resources. It requires JDK 7 or later. import java.io.*; import java.lang.reflect.Array; import java.util.Arrays; class DataInputStreamDemo { public static void main(String args[]) throws IOException { //writing the data. try ( DataOutputStream dout = new DataOutputStream(new FileOutputStream("file.dat")) ) { dout.writeBytes("1"); dout.writeFloat(4.4545f); dout.writeUTF("geeksforgeeks"); dout.writeChars("GeeksforGeeks\n"); dout.writeBytes("ABCDEFG"); } catch(FileNotFoundException ex) { System.out.println("Cannot Open the Output File"); return; } // reading the data back. try ( DataInputStream din = new DataInputStream(new FileInputStream("file.dat")) ) { //illustrating readByte() method byte t=din.readByte(); //illustrating readFloat() method float u=din.readFloat(); //illustrating readUTF() method String temp=din.readUTF(); //illustrating readLine() method String temp1=din.readLine(); System.out.println("Values: " + t +" "+" "+u+" "+temp+" "+temp1 ); //illustrating skipBytes() method //skipping "AB" din.skipBytes(2); //illustrating readFully() method byte[] b=new byte[4]; din.readFully(b,0,4); System.out.println(Arrays.toString(b)); } catch(FileNotFoundException e) { System.out.println("Cannot Open the Input File"); return; } } } Output: Values: 49 4.4545 geeksforgeeks GeeksforGeeks [67, 68, 69, 70] Create Quiz Comment K kartik 0 Improve K kartik 0 Improve Article Tags : Java Java-Library Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like