File Write - PrintStream append

前端 未结 2 1777
耶瑟儿~
耶瑟儿~ 2020-11-28 12:35

I am trying to append some information into a text file, but the file only shows the last element written.

There are many Engineers, but it prints to th

2条回答
  •  遥遥无期
    2020-11-28 13:20

    I don't see where you are closing the file. I don't see you reading anything either.

    I assume you want to append to the file instead of overwriting it each time. In that case you need to use the append option of FileOutputStream as this is not the default behaviour.

    PrintStream writetoEngineer = new PrintStream(
         new FileOutputStream("Engineer.txt", true)); 
    

    BTW: e.toString() + " " is almost the same as e + " " except it doesn't throw an exception if e is null.

提交回复
热议问题