Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中读取日志文件_Java_Logging_File Io - Fatal编程技术网

在Java中读取日志文件

在Java中读取日志文件,java,logging,file-io,Java,Logging,File Io,我试图用Java读取一个日志文件,该文件在每个页面视图中只显示一行。如果我使用下面的方法读取我的文件,它仍然会读取整个日志文件,还是会在第一页之后停止,因为该页上没有其他行可读取 try{ FileInputStream fstream = new FileInputStream(fileName); BufferedReader br = new BufferedReader(new InputStreamReader(fstream));

我试图用Java读取一个日志文件,该文件在每个页面视图中只显示一行。如果我使用下面的方法读取我的文件,它仍然会读取整个日志文件,还是会在第一页之后停止,因为该页上没有其他行可读取

    try{
           FileInputStream fstream = new FileInputStream(fileName);
           BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
           String strLine;
           //Reading line by line
           while ((strLine = br.readLine()) != null)   {
             getUsersForPage(strLine);
           }
           br.close();
        } catch (Exception e) {
             System.err.println("Error: " + e.getMessage());
        }

唯一可以停止
while
循环的是当
getUsersForPage
抛出异常时,因此如果它没有抛出异常,那么它将读取整个文件。正如Jesper所说,该文件很可能被完全读取。最终得到什么取决于
getUsersForPage(line)
的功能。谢谢。它运行得很好。