AIM:PROGRAM TO READ FILE CONTENTS AND DISPLAY THEM ALONG WITH LINE NUMBERS.

i tried the following code but unable to get the right output :


import java.io.*;
class file_display
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter file name");
String name=dis.readLine();
FileOutputStream fout=new FileOutputStream(name);
System.out.println("enter text & '@' to end");
char ch;
while((ch=(char)dis.read())!='@')
fout.write(ch);
fout.close();
System.out.println("entered data is : ");
FileInputStream fin=new FileInputStream(name);
int i=1,c,l=0,w=0,cc=0;
System.out.print(i);
while((c=fin.read())!=-1)
if(c=='\n')
System.out.print(++i);
System.out.print((char)c);
fin.close();
}
}

plz help me getting the correct output.....