java快速计算文本文件行数

File test= new File("test.txt");
long fileLength = test.length();
LineNumberReader rf = null;
try {
rf = new LineNumberReader(new FileReader(test));
if (rf != null) {
int lines = 0;
rf.skip(fileLength);
lines = rf.getLineNumber();
rf.close();
}
} catch (IOException e) {
if (rf != null) {
try {
rf.close();
} catch (IOException ee) {
}
}
}

你可能感兴趣的:(java)