0

要扫描文件以查找我正在使用scanner.findWithinHorizo​​n 的某些模式,它会给出不正确的结果。这是我所做的:

content = readFile(<filepath>, Charset.forName( "utf-8"));
Pattern pattern =   Pattern.compile(wordtoMatch ,Pattern.MULTILINE);
while ((s !=null) && (null != s.findWithinHorizon(pattern,0) )) {

    MatchResult mr = s.match();


     System.out.printf("Word found: %s at index %d to %d.%n", mr.group(),
             mr.start(), mr.end());
}

结果:

 Word found: gets( at index 5991 to 5996.
    .......

    Word found: gets( at index 8170 to 8175.

    Word found: gets( at index 8180 to 8185.

    Word found: gets( at index 3 to 8.  

----------->这里正在重新启动它应该像8188一样继续

    Word found: gets( at index 11 to 16.

   .....
    Word found: gets( at index 18765 to 18770.

    Word found: gets( at index 18774 to 18779.

------------------------------------------------------------------------------

我不确定是什么导致了这种情况,任何指针都会很有帮助。

我检查了 IOException 及其 null

4

0 回答 0