java按行读取文件并计算行数

来源:互联网 发布:剑灵捏脸数据人男 编辑:程序博客网 时间:2024/05/16 09:23

我是php开发,最近因为项目需要,需临时学习java开发。读取文件,是在项目中很重要的功能,同时也是我练手的第一个功能。下面的函数实现了按行读取文件内容,并将行数记录功能。

  • 代码
public static int readFileLineCounts() throws IOException{    int count = 0;    File file = new File("/tmp/test.log");    FileInputStream fis = new FileInputStream(file);    InputStreamReader isr = new InputStreamReader(fis);    BufferedReader br = new BufferedReader(isr);    while((br.readLine())!=null){        count++;    }    return count;}
阅读全文
0 0