在文件中搜索字符串“$DATA ASCII”时,我的 findWithinHorizon 方法返回 null。相同的方法可以找到其他字符串,例如“Array Start”。
这是我搜索文件的代码:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class SearchingFilesMain {
public static void main(String[] arg) {
String checker;
String pattern1= "$DATA ASCII";
try {
Scanner scan = new Scanner(new BufferedReader(new FileReader(
"C:\\Users\\User\\Desktop\\asciiTracks.txt")));
checker = scan.findWithinHorizon(pattern1,0);
System.out.println(checker);
} catch (FileNotFoundException e) {
System.out.println(e.getStackTrace());
}}}
这是文件的一部分,如 notepad++ 所示:
$DATA ASCII
$DATA_INFO
Array Start = 0 * 126
$PROCESSING_INFO
Generation Time = 13:53:42
$GENERAL
Tx Time = 450.079
Tx Time Abs = 1080309222.55633
Tx Clock = 13:53:42
Cerb Tracker Whole Time = 0.015
Num contacts = 699
$DATA ASCII
$DATA_INFO
Array Start = 0 * 127
$PROCESSING_INFO
Generation Time = 13:53:45
$GENERAL
Tx Time = 453.219
Tx Time Abs = 1080309225.69626
Tx Clock = 13:53:45
Cerb Tracker Clutter processing = 0.016
Cerb Tracker Whole Time = 0.016
Num contacts = 666
$DATA ASCII
我不知道为什么 then 方法无法搜索此代码以找到“$DATA ASCII”,有人能想到任何原因吗?