title: bufferedwriter truncate the string
body: <p>I write a String to a file, the string is very long, about 100K, here is my code:</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      String s = "kkkk";
  
      BufferedWriter bw = new BufferedWriter(new FileWriter("/Users/liaoliuqing/Downloads/1.txt",true),1024);
      bw.write(s);
      bw.flush();
      bw.close();
  }
  </code></pre>
  
  <p>when the string is short, it works well. but when the string is very long, the string will be truncate, and only some character written to the file.</p>
  
  <p>what is the problem?</p>
  
  <p>here is my code, and it works in many threads.</p>
  
  <pre><code>private void writeToFile(String filterName, String messageToWrite)
          throws IOException {
      if(!messageToWrite.contains("2015")){
          LOG.warn(messageToWrite);
      }
      bufferWritter = getBufferWriter(filterName, messageToWrite);
      bufferWritter.write(messageToWrite);
      if(!messageToWrite.contains("2015")){
          LOG.warn(messageToWrite);
      }
      bufferWritter.flush();
  }
  </code></pre>
  
  <p>I pretty sure messageToWrite is the full string, since I log it. but just the latter part of the string is written to the file.</p>
  
  <p>It works in about 10 threads.</p>
  
  <p>I find the problem. when one thread is writting the file, then it is the time for another thread to run, the content of first thread will confuse with 2rd thread.
  I try to incread the buffer size of the bufferwriter by </p>
  
  <pre><code>    returnWriter = new BufferedWriter(new FileWriter(fileName, true),64*1024);
  </code></pre>
  
  <p>but it is not work. it still write just 8192(the default buffer size) to the file.
  how to solve this?</p>