if(e.getActionCommand().equals(\"save to file\"))
{
System.out.println(\"save is pressed\");
StringBuffer fileContent = new StringBuffer();
If you don't have access to a database (local or on a server), the best way will probably to use the Serialization.
Consider using a concrete class to populate your JTable
. So to save the data, you just have to make this class to implement Serializable
, and then write it in a file using an ObjectOutputStream
. Then to retrieve it later use an ObjectInputStream
.
I don't really remember how JTable
works with data, but you will probably have to create a custom Model class that inerhits from AbstractTableModel
, and will contain the data whether in an array or in a List
. But it's better to use a List
since it is a lot more fexible and easy to use. So you can direclty serialize the List, and retrieve when program run next time.