Formating string and writing to a file in java
<p>I have some strings which are to be formated and write to a file,</p>

<p>Sample strings,</p>

<pre><code>text1
text2
text3
text4
text5
text6
text7
text8
text9
text10
text11
text12
text13
</code></pre>

<p>The first 10 lines should come in first column and the remaining lines should come in 2nd column.  from 1st column to second column there should be a space of 30</p>

<p>This is what i tried,</p>

<pre><code>   File f = new File("sample.txt");
        FileWriter fw = new FileWriter(f);
        pw = new PrintWriter(fw);
        String text;

        for(int i=0; i&lt;15; i++){
                text = "text" + i;

                if(i &lt;= 10){
                    pw.format(text + "\n");
                } else{
                    pw.format("%30s",text + "\n");
                }    
            }
        }
</code></pre>

<p>I have attached an image of expected output.</p>

<p><img src="http://i.stack.imgur.com/Ob8OB.png" alt="enter image description here"></p>
