title: Java BufferedWriter very slow - 300 MB of data
body: <p>I'm reading a text file consisting of fixed length records line by line and append some values and then write to another file. </p>
  
  <p>As usual, I used BufferedWriter, and found that it takes around 20 Mins to read, append values and write to another file.</p>
  
  <pre><code>BufferedWriter br = new BufferedReader(new FileReader(infile));
  if (br != null) {
      for (String line; (line= br.readLine()) != null;) {
          i= i+ 1;
          line += "    " + String.format("%09d", i) + "S";
          try {
              bw = new BufferedWriter(new FileWriter("out.txt",
                      true));
              bw.write(line);
              bw.newLine();
              bw.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>This is the code I have used. Reading the whole file and appending the values takes just 7 seconds, but writing to file seems to be slow. I know BufferedWriter cannot be this much slower. I didnt increase the buffer size as i'm reading line by line and for the same reason didnt try nio.</p>
  
  <p>Suggest me some way to improve the speed?</p>