title: How to parse a text file and create a database record from it
body: <p>I'm trying to basically make a simple Test Generator. I want a button to parse a text file and add the records to my database. The questions and answers are in a text file. I have been searching the net for examples but I can't find one that matches my situation. </p>
  
  <p>The text file has header information that I want to ignore up until the line that starts with "~ End of Syllabus". I want "~ End of Syllabus" to indicate the beginning of the questions. A couple of lines after that look for a line with a "(" in the seventh character position. I want that to indicate the Question Number line. The Question Number line is unique in that the "(" is in the seventh character position.  I want to use that as an indicator to mark the start of a new question. In the Question Number line, the first three characters together "T1A" are the Question Group. The last part of the T1A*<em>01</em>* is the question number within that group.</p>
  
  <p>So, as you can see I will also need to get the actual question text line and the answer lines as well. Also typically after the four Answer lines is the Question Terminator indicated by "~~". I don't know how I would be able to do this for all the questions in the text file. Do I keep adding them to an array String? How would I access this information from the file and add it to a database. This is very confusing for me and the way I feel I could learn how this works is by seeing an example that covers my situation. Here is a link to the text file I'm talking about:<a href="http://pastebin.com/3U3uwLHN" rel="nofollow">http://pastebin.com/3U3uwLHN</a> </p>
  
  <p>Code: </p>
  
  <pre><code>public static void main(String args[]) {
  
      String endOfSyllabus = "~ End of Syllabus";
      Path objPath = Paths.get("2014HamTechnician.txt");
      String[]  restOfTextFile = null;
  
      if (Files.exists(objPath)){
  
          File objFile = objPath.toFile();
          try(BufferedReader in = new BufferedReader(
                  new FileReader(objFile))){
  
              String line = in.readLine();
              List&lt;String&gt; linesFile = new LinkedList&lt;&gt;();
  
              while(line != null){
                  linesFile.add(line);  
                  line = in.readLine();
              }
  
              System.out.println(linesFile);
          }
          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);
          }
      });
  }
  </code></pre>