title: Unable to save content in text file using java
body: <p>I read the pdf file using iText Pdf reader. After that i am tying to save content in a text file. I am using following code. But here content is not writing to file. Here, I read the whole pdf page by page but if read only one page then it is writing to file. why this code not able to save whole content in the specified text file. However this code print all the content in the console. can anyone help please where I am wrong?</p>
  
  <pre><code>public class PdfReadExample {
  
      public static void main(String[] args) {
          PdfReader reader;
          String textFromPage;
          BufferedWriter bw=null;
          FileWriter fw=null;
  
          try {
              reader = new PdfReader("pdf location");
              int nPages=reader.getNumberOfPages();
              System.out.println(nPages);
              for(int i = 1; i &lt;=n Pages; i++){
                  textFromPage = PdfTextExtractor.getTextFromPage(reader, i);
                  System.out.println("page" + i + " " + textFromPage);
                  fw = new FileWriter("input.txt", true);
                  bw = new BufferedWriter(fw);
                  bw.write(textFromPage);
  
                  System.out.println(textFromPage);
              }
  
              reader.close();
              bw.close();
              fw.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  } 
  </code></pre>