You are on page 1of 3

//SOUVIK & SOUMODIP

A program to display from a binary file in the hard disk 'stu.dat'.

import java.io.* ;
public class BinaryOutput
{
static String fileName = "Stu.dat";
public static void main(String[ ] args)
{
boolean EOF = false;
try
{
FileInputStream fr =new FileInputStream(fileName);
DataInputStream dr = new DataInputStream(fr);
while(!EOF)
{
try
{
int rno ;
float marks;
rno = dr.readInt() ;
System.out.println ("Rollno"+ rno);
marks= dr.readFloat();
System.out.println ("Marks"+ marks);
}
catch (EOFException el)
{
System. out.println("end of file");
EOF = true;
}
catch (IOException e)
{
System.err.println(e);
}
}
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
}
}
}
SAMPLE OUTPUT:

Rollno1
Marks89.0
Rollno6
Marks34.0
Rollno7
Marks89.0
Rollno9
Marks76.0
Rollno8
Marks56.0
end of file

You might also like