0

ファイルは、私が必要としない約 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);
        }
    });
}
4

3 に答える 3

0

どうですか:

boolean found = false;
for (String line; (line = in.readLine()) != null;) {
    found = found || line.equals(endOfSyllabus); 
    if (found) {
         // process line
    }
}
于 2013-05-20T19:51:39.413 に答える
0

You can try this if you know the exact string that you are looking

if (lineString.startsWith("insert exact string")) {
    // ...
}
于 2013-05-20T19:34:04.877 に答える