title: bufferedReader readline=null
body: <p>im trying to write a class where it would take a text file,reverse its contents and write it back. The way i want to do it is to write the lines in a <code>String[]</code> array,reverse the lines and then write the text back to the text file. Problem is, when I start writing to the String array, it writes off only nulls and i know the text file is not empty. Im using a copy of the <code>BufferedReader</code> to read the lines. I can't seem to understand where am i wrong. When I initialize the <code>String</code> array textFile like down in the code, i have no problems reversing, but when i use the  </p>
  
  <pre><code>String[] textFile = new String[getNumberOfLines ()]; 
  </code></pre>
  
  <p>method, it doesnt work.</p>
  
  <pre><code>public void reverse() throws IOException {
      BufferedReader reader = new BufferedReader(new FileReader(WORK_FOLDER_LOCATION + FILE_NAME));
      String[] textFile = new String[3];
      try {
          for (int i = 0; i &lt; textFile.length; i++) {
              textFile[i] = reader.readLine();
              textFile[i] = reverseLine(textFile[i]);
          }
      } catch (IOException e) {
          throw new IOException("There was a problem while operating with the reader.");
      } finally {
          reader.close();
      }
      writeReverseText(textFile);
  }
  
  private int getNumberOfLines(BufferedReader reader) throws IOException {
      BufferedReader linesReader = reader;
      int counter = 0;
      try {
          while (linesReader.readLine() != null) {
              counter++;
          }
          linesReader.close();
      } catch (IOException e) {
          throw new IOException("There was a problem while counting the lines");
      }
      return counter;
  }
  
  private String reverseLine(String string) {
      StringBuilder reversedString = new StringBuilder(string).reverse();
      System.out.println(reversedString);
      return reversedString.toString();
  
  }
  
  private void writeReverseText(String[] textFile) throws IOException {
      BufferedWriter writer = new BufferedWriter(new FileWriter(WORK_FOLDER_LOCATION + FILE_NAME));
      for (int i = 0; i &lt; textFile.length; i++) {
          writer.append(textFile[i]);
          writer.append(System.lineSeparator());
      }
      writer.close();
  }
  </code></pre>
  
  <p><strong>EDIT</strong> I managed to solve the issue but changing the <code>getNumberOfLines()</code> method:</p>
  
  <pre><code>private int getNumberOfLines() throws IOException {
      BufferedReader linesReader = new BufferedReader(new FileReader(WORK_FOLDER_LOCATION + FILE_NAME));
  </code></pre>
  
  <p>Hope this helps to the others, i would love to know why the previous code didn't work.</p>