title: Splitting a text file into multiple files by specific character sequence
body: <p>I have a file with the following format.</p>
  
  <pre><code>.I 1
  .T
  experimental investigation of the aerodynamics of a
  wing in a slipstream . 1989
  .A
  brenckman,m.
  .B
  experimental investigation of the aerodynamics of a
  wing in a slipstream .
  .I 2
  .T
  simple shear flow past a flat plate in an incompressible fluid of small
  viscosity .
  .A
  ting-yili
  .B
  some texts...
  some more text....
  .I 3
  ...
  </code></pre>
  
  <p>"<strong><em>.I 1</em></strong>" indicate the beginning of chunk of text corresponding to <strong><em>doc ID1</em></strong> and "<strong><em>.I 2</em></strong>" indicates the beginning of chunk of text corresponding to <strong><em>doc ID2</em></strong>.</p>
  
  <p><strong>what I need</strong> is read the text between ".I 1" and ".I 2" and save it as a separate file like "DOC_ID_1.txt" and then read the text between ".I 2" and ".I 3"
  and save it as a separate file like "DOC_ID_2.txt" and so on. <em>lets assume that the number of .I # is not known.</em></p>
  
  <p>I have tried this but cannot finish it. any help will be appreciated </p>
  
  <pre><code>String inputDocFile="C:\\Dropbox\\Data\\cran.all.1400";     
  try {
       File inputFile = new File(inputDocFile);
       FileReader fileReader = new FileReader(inputFile);
       BufferedReader bufferedReader = new BufferedReader(fileReader);
       String line=null;
       String outputDocFileSeperatedByID="DOC_ID_";
       //Pattern docHeaderPattern = Pattern.compile(".I ", Pattern.MULTILINE | Pattern.COMMENTS);
       ArrayList&lt;ArrayList&lt;String&gt;&gt; result = new ArrayList&lt;&gt; ();
       int docID =0;
       try {
            StringBuilder sb = new StringBuilder();
            line = bufferedReader.readLine();
            while (line != null) {
                if (line.startsWith(".I"))
                { 
                   result.add(new ArrayList&lt;String&gt;());
                   result.get(docID).add(".I");
                   line = bufferedReader.readLine();
  
                   while(line != null &amp;&amp; !line.startsWith(".I")){
                      line = bufferedReader.readLine();
                      }
                       ++docID;
                }        
                else line = bufferedReader.readLine();
            }
  
        } finally {
            bufferedReader.close();
        }
     } catch (IOException ex) {
        Logger.getLogger(ReadFile.class.getName()).log(Level.SEVERE, null, ex);
     }
  </code></pre>