You should open file like this for appending string in the file
new FileOutputStream(file, true)
Creates a file output stream to write to the file represented by the specified File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.
But Java serialization does not support "appending". you can't write an ObjectOutputStream
to a file, then open the file again in append mode and write another ObjectOutputStream
to it. you have to re-write the entire file every time. (i.e. if you want to add objects to the file, you need to read all the existing objects, then write the file again with all the old objects and then the new objects).
I would sugest you to use DataOutputStream
public void writeSelling(List<String> wordList) throws IOException {
fileOutPutStream = new FileOutputStream (file,true);
DataOutputStream write =new DataOutputStream(fileOutPutStream);
for (String s : wordList){
d.writeUTF(s);
}
write.close();
}