该文件以大约 200 行我不需要的背景信息开头。我试图跳过/忽略这 200 行,直到找到一个字符串。找到此字符串后,我希望能够继续处理文本文件的其余部分。
示例文本文件:(直到第 240 行是我需要跳过/忽略的所有行) http://pastebin.com/5Ay4ad6y
public static void main(String args[]) {
String endOfSyllabus = "~ End of Syllabus";
Path objPath = Paths.get("2014HamTechnician.txt");
if (Files.exists(objPath)) {
File objFile = objPath.toFile();
try (BufferedReader in = new BufferedReader(new FileReader(objFile))) {
String line = in.readLine();
while (line != null) {
line = in.readLine();
}
if(endOfSyllabus.equals(line) ){
restOfTextFile = line.split(endOfSyllabus);
}
}
System.out.println(restOfTextFile[0]);
}
catch(IOException e){
System.out.println(e);
}
}
else{
System.out.println(
objPath.toAbsolutePath() + " doesn't exist");
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new A19015_Form().setVisible(true);
}
});
}