package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
*
* @author hf
**@email admin1433@gmail.com
*/
public class FileOpenTest {
private int count = 0;
/**
*
* @param filePath
* @return read the file to record line;
*/
private FileOpenTest(String filePath) {
File f = new File(filePath);
try {
BufferedReader br = new BufferedReader(new FileReader(f));
while (br.ready()) {
br.readLine();
count ++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
private int getCount() {
return count;
}
public static void main(String[] args) {
String filePath = "D:\\MrTool.java"; //local file root
FileOpenTest fot = new FileOpenTest(filePath);
System.out.println(fot.getCount());
}
}
java 快速读取一个文本文件的行数
最新推荐文章于 2021-12-06 16:54:36 发布