title: Order in column a N number of number rows on a txt file with java
body: <p>I was trying to make an assignment my teacher gave and I have to order in column a set of number rows in a text file with Java
  Disclaimer: my teacher doesn't want the Scanner class for this assigment: the sample data is this:</p>
  <pre><code>17,10,
  6, 90,
  11
  </code></pre>
  <p>The result should be this:</p>
  <pre><code>17
  10
  6
  90
  11
  </code></pre>
  <p>My code is this:</p>
  <pre><code>package esercizio.prova.verifica;
  import java.io.*;
  public class EsercizioProvaVerifica {
  
  public static void main(String[] args) {
      
      //read the file and put content in a String array
      String[] str={};
      String line = &quot;&quot;;
      try{
          BufferedReader reader = new BufferedReader(new FileReader(&quot;C:\\sorgente\\file.txt&quot;));
          int i=0;
      
          while((line=reader.readLine())!=null || i&lt;str.length){
              line = reader.readLine();
              System.out.println(line + i);
              str[i]=line;
              i++;
         }
      
         reader.close();
      } catch(IOException e){}
      
      
      // Write array on file
      for (int i=0;i&lt;str.length;i++){
          System.out.println(str[i]);
      }
      try{
          BufferedWriter bw = new BufferedWriter(new FileWriter(&quot;C:\\sorgente\\file.txt&quot;));
          for (int i = 0; i &lt; str.length; i++) {
               bw.write(str[i] + &quot;\n&quot;+ &quot;&quot;);
          }
          bw.close();
       }catch (IOException e1){}}}
  </code></pre>
  <p>The problem is everytime I run the program, the text in the file disappears and Java returns the following output:</p>
  <pre><code>run:
  6, 90,0
  Exception in thread &quot;main&quot; java.lang.ArrayIndexOutOfBoundsException: 0
  at esercizio.prova.verifica.EsercizioProvaVerifica.main(EsercizioProvaVerifica.java:16)
  C:\Users\franc\AppData\Local\NetBeans\Cache\8.2rc\executor-snippets\run.xml:53: Java returned: 1
  BUILD FAILED (total time: 0 seconds)
  </code></pre>
  <p>I searched for hours and I can't find the problem, Can someone help? Thanks a lot.</p>