title: Java BufferWriter not completing write of file
body: <p>Here is my situation. I am writing <code>&lt;!ENTITY&gt;</code> declarations to an XML file. I read in the original XML file using a Scanner. As the scanner reads the input file i write the lines out to the BufferedWriter. When the scanner is on line 2 i write my <code>&lt;!ENTITY&gt;</code> values from an ArrayList that was passed to the method. My <code>&lt;!ENTITY&gt;</code> values write no problem. Issue I am having is that I am only getting 400 or so lines of the file written to the output file.</p>
  
  <p><a href="https://i.stack.imgur.com/B4YcJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B4YcJ.png" alt="enter image description here"></a></p>
  
  <p>I've read through a few posts on here regarding BufferedWriters not completing writes to files, and all seemed to point to ensuring the writer is closed. I have closed my writer object.</p>
  
  <pre><code>private void addEntityRefs(Map&lt;String, String&gt; icns, File xml)
  {
      String path = xml.getAbsolutePath().substring(0,xml.getAbsolutePath().lastIndexOf(File.separator)+1);
      ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
      Scanner reader = null;
      BufferedWriter writer = null;
      for(Map.Entry&lt;String, String&gt; e : icns.entrySet())
      {
         list.add(e.getValue());
      }
      try
      {
          reader = new Scanner(xml);
          //standardOut.println("Reading " + xml.getName());
          //System.out.println();
          int c = 0;
          String output = path + "out2.xml";
          writer = new BufferedWriter(new FileWriter(new File(output)));
  
          while(reader.hasNextLine())
          {
              c++;
              if(c == 1)
              {
                  writer.append(reader.nextLine().replaceAll("\\s", " "));
              }
              else if(c == 2)
              {
                  System.out.println("writing entities @ line 2");
                  writer.append("\n&lt;!DOCTYPE pm [\n");
  
                  for(int i = 0; i &lt; list.size(); i++)
                  {
                      writer.append("&lt;!ENTITY " + list.get(i).trim() + " SYSTEM \"" + list.get(i).trim() + ".cgm\" NDATA cgm&gt;\n");
                  }
                  writer.append("&lt;!NOTATION cgm PUBLIC \"cgm\" \"\"&gt;\n]&gt;\n");
              }
              else
              {
                  System.out.println("Writing line " + c);
                  writer.append(reader.nextLine().replaceAll("\\s", " ")+ "\r");
              }
  
          }
  
      } 
      catch (FileNotFoundException ex) 
      {
          Logger.getLogger(AARPdfGenUI.class.getName()).log(Level.WARN, null, ex);
          JOptionPane.showMessageDialog(this, ex, "File Not Found Exception", JOptionPane.ERROR_MESSAGE);
      } 
      catch (IOException ex) 
      {
          Logger.getLogger(AARPdfGenUI.class.getName()).log(Level.WARN, null, ex);
          JOptionPane.showMessageDialog(this, ex, "IO Exception", JOptionPane.ERROR_MESSAGE);
      }
      finally
      {
          try
          {
              reader.close();
              writer.close();
          }
          catch(Exception e)
          {
              Logger.getLogger(AARPdfGenUI.class.getName()).log(Level.WARN, null, e);
          JOptionPane.showMessageDialog(this, e, "Exception", JOptionPane.ERROR_MESSAGE);
          }
      }
  }
  </code></pre>
  
  <p>The output of the writer is used to generate PDFs. The file being read and <code>&lt;!ENTITY&gt;</code> declarations added to is about 26,000 lines long. Can someone point me to where I have gone wrong? This method works without issue when I run the application from NetBeans, but once I build it and attempt to run from the JAR file is when it stops after about 400 lines.</p>