Unix/Linux“tail-f”的Java IO实现我想知道用什么技术和/或库来实现Linux命令“tail-f”的功能。我本质上是在寻找一些附加/替代的东西。java.io.FileReader..客户端代码可能如下所示:TailFileReader lft = new TailFileReader("application.log");BufferedReader br = new BufferedReader(lft);String line;try {
while (true) {
line= br.readLine();
// do something interesting with line
}} catch (IOException e) {
// barf}缺失的部分是一个合理的实现TailFileReader..它应该能够读取文件打开前存在的部分文件以及添加的行。
3 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
BufferedReader br = new BufferedReader(...);String line;while (keepReading) { line = reader.readLine(); if (line == null) { //wait until there is more of the file for us to read Thread.sleep(1000); } else { //do something interesting with the line }}
keepReading
stopReading()
添加回答
举报
0/150
提交
取消