Appending file results in overwrite (Java)

僤鯓⒐⒋嵵緔 提交于 2019-12-04 10:10:29

Instead of doing

new FileOutputStream(stored_hka);

do

new FileOutputStream(stored_hka, true);

This will open the file stored_hka in append mode instead of overwriting the contents. See the javadoc for FileOutputStream(String name, boolean append) for more information

When you construct your FileWriter or FileOutputStream there's a constructor argument which allows you to put it in append mode:

new FileOutputStream( "/path/to/file", true )

change

FileOutputStream fOut = new FileOutputStream(stored_hka);

to

FileOutputStream fOut = new FileOutputStream(stored_hka, true);

Use the FileOutputStream constructor that includes a boolean for appending

FileInputStream("valid path of file", true);

It will open a file in append mode. Boolean value is for whether you want to open a file in append mode or not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!