DataInputStream readLong() method in Java with Examples Last Updated : 05 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The readLong() method of DataInputStream class in Java is used to read eight input bytes and returns a long value. This method reads the next eight bytes from the input stream and interprets it into long type and returns. Syntax: public final long readLong() throws IOException Specified By: This method is specified by readLong() method of DataInput interface. Parameters: This method does not accept any parameter. Return value: This method returns the long value interpreted by the next eight bytes of the input stream. Exceptions: EOFException - It throws EOFException if the input stream is ended before eight bytes can be read. IOException - This method throws IOException if the stream is closed or some other I/O error occurs. Below programs illustrate readLong() method in DataInputStream class in IO package: Program 1: Assume the existence of file "demo.txt". Java // Java program to illustrate // DataInputStream readLong() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Create long array long[] buf = { 10000000000l, 20000000000l, 30000000000l }; // Create file output stream FileOutputStream outputStream = new FileOutputStream("c:\\demo.txt"); // Create data output stream DataOutputStream dataOutputStr = new DataOutputStream(outputStream); for (long b : buf) { // Write long value to // the dataOutputStream dataOutputStr.writeLong(b); } dataOutputStr.flush(); // Create file input stream FileInputStream inputStream = new FileInputStream("c:\\demo.txt"); // Create data input stream DataInputStream dataInputStr = new DataInputStream(inputStream); while (dataInputStr.available() > 0) { // Print long values System.out.println( dataInputStr.readLong()); } } } Output: Program 2: Assume the existence of file "demo.txt". Java // Java program to illustrate // DataInputStream readLong() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Create long array long[] buf = { 1234567890L, 9876543210L, 12345678910L }; // Create file output stream FileOutputStream outputStream = new FileOutputStream("c:\\demo.txt"); // Create data output stream DataOutputStream dataOutputStr = new DataOutputStream(outputStream); for (long b : buf) { // Write long value to // the dataOutputStream dataOutputStr.writeLong(b); } dataOutputStr.flush(); // Create file input stream FileInputStream inputStream = new FileInputStream("c:\\demo.txt"); // Create data input stream DataInputStream dataInputStr = new DataInputStream(inputStream); while (dataInputStr.available() > 0) { // Print long values System.out.println( dataInputStr.readLong()); } } } Output: References: https://docs.oracle.com/javase/10/docs/api/java/io/DataInputStream.html#readLong() Comment More infoAdvertise with us Next Article DataInputStream readFloat() method in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-IO package Practice Tags : Java Similar Reads 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 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 readFloat() method in Java with Examples The readFloat() method of DataInputStream class in Java is used to read four input bytes and returns a float value. This method reads the next four bytes from the input stream and interprets it into float type and returns. Syntax: public final float readFloat() throws IOException Specified By: This 2 min read DataInputStream readBoolean() method in Java with Examples The readBoolean() method of DataInputStream class in Java is used to read one input byte and if the byte read is zero this method returns false and if the byte read is nonzero then this method returns true. Syntax: public final boolean readBoolean() throws IOException Specified By: This method is sp 2 min read DataInputStream readShort() method in Java with Examples The readShort() method of DataInputStream class in Java is used to read two input bytes and returns a short value. This method reads the next two bytes from the input stream and interprets it into short type and returns. Syntax: public final short readShort() throws IOException Specified By: This me 2 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