Trouble with filewriter overwriting files instead of appending to the end

后端 未结 3 1936
孤城傲影
孤城傲影 2020-11-28 15:00

OK, I\'m having some trouble writing multiple lines to a text file.

the program runs, but it won\'t use new lines each time

when I want it run 4 times, the t

3条回答
  •  佛祖请我去吃肉
    2020-11-28 15:54

    I'm not sure what this code is supposed to do. It throws an error if your input string is more than one character long, because you close your FileWriter inside the loop, then try to write to it again.

    I'm interpreting your question the following way: you're wondering why only the most recent output is in the file. In that case, it's because you didn't create your FileWriter in append mode. Look at the different constructors available for FileWriter, and use the one that allows you to append to the file.

提交回复
热议问题