title: How to print the contents of stringbuilder in each line in a output text file in java
body: <p>I am working with an excel file which is a large one and i have to parse it using apache event library.So now i am somehow able to get the each cell value and contents of each cell and i am storing them in a <code>Struingbuilder</code>.So now my aim is to generate the text file in such a way so that each row and column will be look like the source excel file. I am giving the pic of the structure of the excel file.</p>
  
  <pre><code>XXXXXX  XXXXXXXXXXXX  XXXXXXXX  XXXXXXXXXXX  XXXXXXXXX
  1         DDD          FFFFFF   KKKK            LLLL
  2          KKK          FFFFF   KKK             LLLL
  .............................
  9          KKK          HHH     LL                JJJ
  </code></pre>
  
  <p>So i am getting the file content as </p>
  
  <pre><code>public void endElement(String uri, String localName, String name)
              throws SAXException {
          StringBuilder row = new StringBuilder();
          // Process the last contents as required.
          // Do now, as characters() may be called more than once
          if(nextIsString) {
              int idx = Integer.parseInt(lastContents);
  
              lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
              nextIsString = false;
          }
  
          // v =&gt; contents of a cell
          // Output after we've seen the string contents
          if(name.equals("v")) {
              //System.out.println(lastContents);
  
              if(!lastContents.isEmpty() )
              row.append(lastContents);
  
              /*if(lastContents == null) {
                  row.append("");
              }else {
                  row.append(SEPARATOR);
              }*/
  
              aMethodToParseRow(row);
              try {
                  FileUtils.write(new File("D:\\BM_Amortization_.txt"), formatListToString(pickUpExcelValues));
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
      }
  
      private void aMethodToParseRow(StringBuilder row) {
          StringBuilder sb =  new StringBuilder();
          StringBuilder sb1 =  new StringBuilder();int count =0;
          if(!(row.toString().equals("Loan details") || row.toString().equals("Fixed") || row.toString().equals("3m")|| row.toString().equals("ACT/364")||row.toString().equals("Amounts * EUR 1")||row.toString().equals("Floating") ||row.toString().equals("ACT/365")||row.toString().equals("43100")||row.toString().toString().equals("6m")||row.toString().toString().equals("ACT/ACT")||row.toString().equals("General information")||row.toString().equals("FA - Reporting")||row.toString().equals("Solvency II Reporting")||row.toString().equals("1y")||row.toString().equals("30/360") )) {
              count++;
              if(count&gt;0 &amp;&amp; count&lt;24)
              sb.append(row.toString());
              System.out.println(sb.toString());
          }
          count=0;
      }
  </code></pre>
  
  <p>So the file contains 24 columns , so can i have a code which will place every cell content to the new line after it comes to 24 index in the <code>Stringbuilder</code>?
  Like the <code>Stringbuilder</code> contains all the hedaers and the data so  starting from the begining when it will reach to 24 number in the <code>Stringbuilder</code> it will break the values into a new line with a separtor.</p>