Write a Java program that reads a file and displays the file on the screen, with a line number before each line. - Code

Latest

programs

Monday, October 10, 2011

Write a Java program that reads a file and displays the file on the screen, with a line number before each line.


Write a Java program that reads a file and displays the file on the screen, with a line number before each line.


import java.io.*;
class FileDemo1
{
public static void main(String args[])throws Exception
{
int c=0;
String s="i+ \n is \n java \n program \n";
char buffer[]=new char[s.length()];
s.getChars(0,s.length(),buffer,0);
FileWriter f1=new FileWriter("c:/index.txt");
f1.write(buffer);
f1.close();
FileReader fr=new FileReader("c:/index.txt");
BufferedReader br=new BufferedReader(fr);
String t;
while((t=br.readLine())!=null)
{
c++;
System.out.println(c+t);
}
fr.close();
}
}

No comments:

Post a Comment