You are on page 1of 2

//SOUVIK & SOUMODIP

A program to display from a file in the hard disk 'names.txt'.

import java.io.* ;
public class FileOutput
{
public static void main(String[ ] args) throws IOException
{
FileReader file = new FileReader("names.txt");
BufferedReader fileInput = new BufferedReader(file);
String text ;
int i = 0 ;
while ((text = fileInput.readLine())!=null)
{
i++;
System.out.print("Name" + i + " : ") ;
System.out.println(text);
}
fileInput.close();
}
SAMPLE OUTPUT:

Name1 : Souvik
Name2 : Soumodip
Name3 : Granthik
Name4 : Manish
Name5 : Saurav

You might also like