Same loop giving different output. Java IO

Posted by Nitesh Panchal on Stack Overflow See other posts from Stack Overflow or by Nitesh Panchal
Published on 2010-03-24T10:11:55Z Indexed on 2010/03/24 10:13 UTC
Read the original article Hit count: 214

Filed under:

Hi, I am facing a very strange problem where the same loop keeps giving me different different output on change of value of BUFFER

  final int BUFFER = 100;
        char[] charArr = new char[BUFFER];
        StringBuffer objStringBuffer = new StringBuffer();
        while (objBufferedReader.read(charArr, 0,BUFFER) != -1) {
            objStringBuffer.append(charArr);
        }
 objFileWriter.write(objStringBuffer.toString());

When i change BUFFER size to 500 it gives me a file of 7 kb when i change BUFFER size to 100000 it gives a file of 400 kb where the contents are repeated again and again. Please help. What should i do to prevent this?

© Stack Overflow or respective owner

Related posts about java