Files written with FileWriter are either 32 KB, 24 KB, 16 KB, ... big or empty

Posted by Bernhard V on Stack Overflow See other posts from Stack Overflow or by Bernhard V
Published on 2010-05-17T07:52:01Z Indexed on 2010/05/17 8:00 UTC
Read the original article Hit count: 241

Filed under:
|

Hi,

I read a file into a string, change the first line and then write this string into a new file. I do this through the following code (a little bit shortened):

while(jspIterator.hasNext()){
                    String line = (String) jspIterator.next();
                    if (i == 0) {
                        if (line.startsWith("bla bla") && line.endsWith("yada")) {
                            line = line.replaceFirst("this", "that");
                        }
                    }
                    jspAsString += line;
                    i++;
                }

FileWriter newJspWriter = new FileWriter(newJspFile);
                newJspWriter.write(jspAsString);

Now the files written this way are either 32, 24, 16, 8 KByte big or completely empty. When debugging I see that the String is assembled correctly. When I print the variable jspAsString to the console it also appears correct.

Do you know why FileWriter behaves this way?

© Stack Overflow or respective owner

Related posts about java

Related posts about file-io