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: 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] Comment More infoAdvertise with us Next Article Java.io.DataInputStream class in Java | Set 2 N Nishant Sharma Improve Article Tags : Java Java-Library Practice Tags : Java Similar Reads Java.io.DataInputStream class in Java | Set 1 A data input stream enables an application to read primitive Java data types from an underlying input stream in a machine-independent way(instead of raw bytes). That is why it is called DataInputStream - because it reads data (numbers) instead of just bytes. An application uses a data output stream 3 min read Java.io.FilterInputStream Class in Java Filter Streams filters data as they read and write data in the Input Stream, filters it and pass it on to the underlying Streams. Filter Streams are FilterInputStream FilterOutput Stream FilterInputStream : Java.io.FilterInputStream class works almost like InputStream class in Java but what it does 9 min read Java.io.InputStream Class in Java Java InputStream class is the superclass of all the io classes i.e. representing an input stream of bytes. It represents an input stream of bytes. Applications that are defining a subclass of the Java InputStream class must provide a method, that returns the next byte of input. A reset() method is i 3 min read Java.util.zip.DeflaterInputStream class in Java Implements an input stream filter for compressing data in the "deflate" compression format. Constructor and Description DeflaterInputStream(InputStream in) : Creates a new input stream with a default compressor and buffer size. DeflaterInputStream(InputStream in, Deflater defl) : Creates a new input 3 min read Java.io.DataOutputStream in Java A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in. Let us do discuss the constructor of this class prior to moving ahead to the methods of this class. Constructor: 5 min read Java.io.FilterOutputStream Class in Java java.io.FilterInputStream Class in Java Java.io.FilterOutputStream class is the superclass of all those classes which filters output streams. The write() method of FilterOutputStream Class filters the data and write it to the underlying stream, filtering which is done depending on the Streams. Decla 5 min read Java.util.zip.GZIPInputStream class in Java This class implements a stream filter for reading compressed data in the GZIP file format. Constructors GZIPInputStream(InputStream in) : Creates a new input stream with a default buffer size. GZIPInputStream(InputStream in, int size) : Creates a new input stream with the specified buffer size. Meth 2 min read Java.util.jar.JarInputStream class in Java The JarInputStream class is used to read the contents of a JAR file from any input stream. It extends the class java.util.zip.ZipInputStream with support for reading an optional Manifest entry. The Manifest can be used to store meta-information about the JAR file and its entries. Constructors JarInp 3 min read Java.io.FilterReader class in Java Abstract class for reading filtered character streams. The abstract class FilterReader itself provides default methods that pass all requests to the contained stream. Subclasses of FilterReader should override some of these methods and may also provide additional methods and fields. Constructor : pr 3 min read Java.util.zip.InflaterInputStream class in Java This class implements a stream filter for uncompressing data in the "deflate" compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream. Constructors InflaterInputStream(InputStream in) : Creates a new input stream with a default decompressor and buffe 3 min read Like