/**
 * Determine the number of text lines in a file.
 * @param fileName
 * @return
 */
public static int fileCountLines(String fileName) {
	int count = 0;
	java.io.FileReader fr = null;
	try {
		fr = new java.io.FileReader(new java.io.File(fileName));
	} catch (java.io.FileNotFoundException ex) {
		Ts.printErr(ex);
	}
	java.io.BufferedReader br = new java.io.BufferedReader(fr);
	try {
		while (br.readLine() != null) {
			count++;
		}
	} catch (java.io.IOException ex) {
		Ts.printErr(ex);
	}
	return count;
}
 
public static void printErr(java.lang.Exception ex) {
	printErr(ex.getMessage());
}


Back to JavaHowTo

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett