title: How does BufferedWriter work in java
body: <p>I frequently output text to files. I wonder something: how does <code>BufferedWriter</code>work?</p>
  
  <p>Does it write text on file when I call <code>writer.write(text)</code>? 
  If it doesn't write text,do I need to use flush function to write data?</p>
  
  <p>For example:</p>
  
  <pre><code>       File file = new File("statistics.txt");
          if (!file.exists()) {
              file.createNewFile();
          }
          else
          {
              file.delete();
              file.createNewFile();
          }
          FileWriter fileWritter = new FileWriter(file.getAbsoluteFile(),true);
          BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
          Iterator&lt;Map.Entry&lt;String,Token&gt;&gt; it = listofTakenPairMap.entrySet().iterator();
          int isim_isim=0;
          int isim_fiil=0;
          int zarf_fiil=0;
          while (it.hasNext()) {
              @SuppressWarnings("rawtypes")
              Map.Entry pairs = (Map.Entry)it.next();
              Token token=(Token)pairs.getValue();
              String str=pairs.getKey()+ " = " +token.getCount();
              if(token.getTypeOfPairofToken()==0){//isim-isim
                  isim_isim+=token.getCount();
              }
              else if(token.getTypeOfPairofToken()==1){
                  isim_fiil+=token.getCount();
              }
              else{ //zarf-fiil
                  zarf_fiil+=token.getCount();
              }
              System.out.println(str);
              bufferWritter.write(str);
              bufferWritter.newLine();
              //it.remove(); // avoids a ConcurrentModificationException
          }
          bufferWritter.newLine();
          bufferWritter.write("##############################");
          bufferWritter.newLine();
          bufferWritter.write("$isim_isim sayisi :"+isim_isim+"$");
          bufferWritter.newLine();
          bufferWritter.write("$isim_fiil sayisi :"+isim_fiil+"$");
          bufferWritter.newLine();
          bufferWritter.write("$zarf_fiil sayisi :"+zarf_fiil+"$");
          bufferWritter.newLine();
          bufferWritter.write("##############################");
          bufferWritter.flush();
          bufferWritter.close();
  </code></pre>
  
  <p>If an error occurs in the while loop,the file will be closed without writing data. If I use <code>flush</code> function in the while loop,then why should i use <code>BufferedWriter</code>? Please correct me If I'm wrong.</p>