This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a class Person that has name, country and dob attributes. Assume there are 5 such objects. I am sorting them by their dob. I can print the 5 objects (sorted by their dob) on the console. Now I want to write the output to a txt file. I tried using BufferedWriter and FileWriter. But only the fifth object gets written into the file. In other words, the objects get over written on the file.
Can some one give me code snippet or guidance as to how can I solve this problem of writing objects into a file.
Originally posted by Jeanne Boyarsky: Are you using the constructor for FileWriter that takes two parameters? The first is the file. The second is a boolean for whether you want to append or overwrite the contents.
Joined: Oct 31, 2008
I am using the FileWriter that takes one argument i.e. the file name.
Can you suggest me what changes should I make in the code?