小编Ste*_*lds的帖子

Java Scanner不会关注文件

试图拖尾/解析一些日志文件.条目以日期开头,然后可以跨越多行.

这有效,但是没有看到要提交的新条目.

File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");

while (true) {
    while(src.hasNext()){
    System.out.println("[ " + src.next() + " ]");
    }
}
Run Code Online (Sandbox Code Playgroud)

看起来不像Scanner的next()或hasNext()检测到新的文件条目.

任何想法我还能实现,基本上,一个带有自定义分隔符的tail -f.


好的 - 使用凯利的建议我正在检查和刷新扫描仪,这是有效的.谢谢 !!

如果有人有改进建议PLZ吗!

File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");

while (true) {
    while(src.hasNext()){
    System.out.println("[ " + src.next() + " ]"); …
Run Code Online (Sandbox Code Playgroud)

java io tail java.util.scanner

6
推荐指数
1
解决办法
897
查看次数

标签 统计

io ×1

java ×1

java.util.scanner ×1

tail ×1