我正在尝试弄清楚如何连续读取一个文件,一旦添加了新行,就输出这一行。 我正在使用一个睡眠线程来做到这一点,但它似乎只是在整个文件中全部运行并退出程序。您有什么建议我做错了什么吗?
以下是我的代码:
以下是我的代码:
import java.io.*;
import java.lang.*;
import java.util.*;
class jtail {
public static void main (String args[])
throws InterruptedException, IOException{
BufferedReader br = new BufferedReader(
new FileReader("\\\\server01\\data\\CommissionPlanLog.txt"));
String line = null;
while (br.nextLine ) {
line = br.readLine();
if (line == null) {
//wait until there is more of the file for us to read
Thread.sleep(1000);
}
else {
System.out.println(line);
}
}
} //end main
} //end class jtail
提前感谢您。
更新:我已将代码中的行 "while (br.nextLine ) {" 更改为 "while (TRUE) {"。
in
是什么? - Simon Nickersonwhile (br.nextLine)
,nextLine不是BufferedReader的有效字段。
- user85421