要扫描某个模式的文件我正在使用scanner.findWithinHorizon,它会给出不正确的结果。 这就是我所做的:
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.
-----------&gt;它正在重新启动它应该继续像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