The Artima Developer Community
Sponsored Link

Java Answers Forum
Counting lines in text file

1 reply on 1 page. Most recent reply: Jul 27, 2003 8:08 AM by FredrikN

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Chris Brooks

Posts: 6
Nickname: bioheel
Registered: Jul, 2003

Counting lines in text file Posted: Jul 27, 2003 7:42 AM
Reply to this message Reply
Advertisement
Probably a straightforward task but I am still learning (self-teaching with a book) and can't figure out how to do this. Can anyone help? There doesn't seem to be any built-in function to do this.


FredrikN

Posts: 22
Nickname: fredrikn
Registered: Jul, 2003

Re: Counting lines in text file Posted: Jul 27, 2003 8:08 AM
Reply to this message Reply
Hi
This might help you...


int count = 0;

FileReader fr = new FileReader("yourFile.txt");
BufferedReader inFile = new BufferedReader(fr);

line = inFile.readLine();

while(line != null)
{
line = inFile.readLine();
count++;
}

System.out.println("There are " + count + " lines in your file");

Flat View: This topic has 1 reply on 1 page
Topic: Problem with changing of BufferSize (audio streaming/ JMF) Previous Topic   Next Topic Topic: Opening a browser by passing an argument??

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use