Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Aysel Kaya   on Jan 31 In Java Category.

  
Question Answered By: Vicki Fields   on Jan 31

Counting the nos. of lines in a file  is simple, you first create a FileReader
class object on the file that you want to use... then wrap this with
BufferedReader class object... now run a while loop and read the content of the
file line  by line and increment a counter inside the loop. at the end of the
loop the counter will give the number  of lines in the file...

eg

consider your input file is input.txt

write this code in the main method
{
int count = 0;
FileReader fr = new FileReader("input.txt";
BufferedReader br = new BufferedReader(fr);
while(br.readLine() != null)
count++;
System.out.println("The Number of lines in the file is : " + count);
}

Share: 

 
 
Didn't find what you were looking for? Find more on getting the total amount of line in java file Or get search suggestion and latest updates.


Tagged: