to persist the data of a dialog box in java

后端 未结 3 1117
天涯浪人
天涯浪人 2021-01-20 19:37
if(e.getActionCommand().equals(\"save to file\"))
    {
        System.out.println(\"save is pressed\");
        StringBuffer fileContent = new StringBuffer();
              


        
3条回答
  •  没有蜡笔的小新
    2021-01-20 19:55

    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.

提交回复
热议问题