DataInputStream ReadInt() Example

reads the next four bytes of this input stream, interpreted as an int.


DataInputStreamclass ReadInt() method example. This example shows you how to use ReadInt() method.This method reads the next four bytes of this input stream, interpreted as an int.

Here is the code:-
/**
 * @Program that reads the next four bytes of this input stream, interpreted 
    as an int. 
 * ReadInt.java 
 * Author:-RoseIndia Team
 * Date:-07-jun-2008
 */
import java.io.*;
public class ReadInt {
public static void main(String[] args)throws IOException {
 int iI = 1134;
        FileOutputStream fos = new FileOutputStream("Linux.txt");
        DataOutputStream dos = new DataOutputStream(fos);
        dos.writeInt(iI);
        dos.flush();
        dos.close();
        FileInputStream fis = new FileInputStream("Linux.txt");
        DataInputStream dis = new DataInputStream(fis);
        int i=dis.readInt();
        System.out.println("The next four bytes of this input stream is: "+i);
    }

}

Output of the Program
  The next four bytes of this input stream is: 1134

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US