0

I suppose to write the records to a text file. However every time i re-log in and add a record.The previous record will be rewrite. >.<''

public void addRecords(){
		getInfo();
		FileWriter fWriter = null;
		BufferedWriter writer = null;
		try {
			fWriter = new FileWriter("PassengerInfo.txt");
			writer = new BufferedWriter(fWriter);
			writer.write(name);
			writer.write(";");
			writer.write(phone);
			writer.write(";");
			writer.write(nationality);
			writer.write(";");
			writer.write(IC);
			writer.newLine();
			
			writer.close();
		}catch (IOException e) {
			JOptionPane.showMessageDialog(null,"FILE NOT EXIST");
		}
	}

Are there any way to keep the record?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by hao90
0

I think when you instantiate your instance of FileWriter you need to do so in appendable mode. to do that, you write as follows:
new FileWriter(PassengerInfo.txt", true);

let me know if that works.

Edited by bibiki: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.