Displaying contents of a file

Aim: 
To write a java program that reads a file and displays the file on the screen, with a line number before each line.

Description: 
The FileInputStream class creates an InputStream that we can use to read bytes from a file. When a FileInputStream is created, it is opened for reading. To display a line number for each line at the time of reading, declare a variable of type int and initialize it with 1 and increment the variable by 1 whenever a new line character is encountered.

Program:
import java.io.*;
class FileRead
{
public static void main(String args[]) throws IOException
{
int ch,ctr=1;
String fname;
BufferedReader br = new BufferedReader(new InputStreamReader (
System.in));
System.out.print("Enter a file name: ");
fname=br.readLine();
FileInputStream fin =new FileInputStream(fname);
System.out.print(ctr+" ");
while((ch=fin.read())!=-1)
{
System.out.print((char)ch);
if(ch=='\n')
{
ctr++;
System.out.print(ctr+" ");
}
}
fin.close();
}
}