Hi guys!
I am making a quiz. The questions are stored in a binary file. I made an option in the quiz where a user can add a question to the binary file. Altough this works, the problem is that whenever a user enters a new question is just overwrites the whole file, instead of adding it to the rest of the questions in the binary file. Do i have something wrong? Thanks a lot. :-)
This is the piece of code that adds a question to binary file:
I am making a quiz. The questions are stored in a binary file. I made an option in the quiz where a user can add a question to the binary file. Altough this works, the problem is that whenever a user enters a new question is just overwrites the whole file, instead of adding it to the rest of the questions in the binary file. Do i have something wrong? Thanks a lot. :-)
This is the piece of code that adds a question to binary file:
Code:
try {
String question = JOptionPane.showInputDialog(null, "Enter new question");
File aFile = new File( "rocks.dat" );
FileOutputStream aFileOutStream = new FileOutputStream ( aFile );
DataOutputStream aDataOutStream = new DataOutputStream ( aFileOutStream );
aDataOutStream.writeUTF( question );
aFileOutStream.close();
}catch(IOException event){
System.out.println("There was a problem:" + e);
}
Comment