SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 395.4k

code correction @no of lines in file ? just one line

Oct 28 2013 3:56 AM
Hi

QuestionWrite a Java program that process and determines the number of lines in a file.


Please look at the below code .. at while(args[i] != null) i am getting continuous exception 

import java.io.*;
class cntlines
{
public static void main(String args[]) throws IOException
{
Try
{
FileReader fr;
BufferedReader br;
File f;
String str;
int i=0,cnt=0;
while(args[i] != null)
{
f = new File(args[i]);
fr = new FileReader(f);
br = new BufferedReader(fr);
while((str = br.readLine()) != null)
cnt++;
System.out.println("File Name : " + f.getName() + " Total Lines : " + cnt);
cnt = 0;
i++;
fr.close();
}
}
catch(FileNotFoundException e)
{
System.out.println("File Not Found");
}
catch(IOException e)
{
System.out.println("Exception : " + e);
}
}
}



cheers ty ..


Answers (1)