Results 1 to 1 of 1
-
How to get the count of all the lines in a file
This example code will read the file (MyFile.txt) using the LineNumberReader and print all the line to the console and extracts the total number of line using the getLineNumber() method of the LineNumberReader.
Java Code:import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; public class LineReaderExp { public static void main(String[] args) throws Exception { LineNumberReader lineCounter = new LineNumberReader( new InputStreamReader(new FileInputStream("C:\\MyFile.txt"))); String nextLine = null; try { while ((nextLine = lineCounter.readLine()) != null) { if (nextLine == null) break; System.out.println(nextLine); } System.out.println("Total number of line in this file " + lineCounter.getLineNumber()); } catch (Exception done) { done.printStackTrace(); } } }
Similar Threads
-
count character in text file as input file
By aNNuur in forum New To JavaReplies: 7Last Post: 03-25-2010, 04:01 PM -
Getting row count
By Java Tip in forum Java TipReplies: 0Last Post: 02-11-2008, 08:49 AM -
how to count 2 inserts together?
By kim85 in forum New To JavaReplies: 0Last Post: 01-20-2008, 11:25 AM -
Getting row count from executeQuery()
By Java Tip in forum Java TipReplies: 0Last Post: 12-05-2007, 02:31 PM -
how to edit lines.
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 04:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks