if(e.getActionCommand().equals("save to file"))
{
System.out.println("save is pressed");
StringBuffer fileContent = new StringBuffer();
TableModel tModel = m_table.getModel();
for (int i = 1; i < tModel.getRowCount(); i++)
{
for(int j=0;j<tModel.getColumnCount();j++)
{
Object cellValue = tModel.getValueAt(i, j);
// ... continue to read each cell in a row
fileContent.append(cellValue);
// ... continue to append each cell value
fileContent.append(" ");
}
fileContent.append("\n");
}
FileWriter fileWriter;
try {
fileWriter = new FileWriter(new File("data.txt"));
fileWriter.write(fileContent.toString());
fileWriter.flush();
fileWriter.close();
}
catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
I have created a JDialog
in which there is a table. I am able to save the table data into the file on a button click, but what i want to do is to keep that data persisted in the table so when the next time the program is run, that data is available and displayed in the table when a confirm button is pressed. Though I read about Java persistence and Java serialization concepts, I'm not getting the clear idea which technique is appropriate and how to use for this problem.