to persist the data of a dialog box in java

后端 未结 3 1029
天涯浪人
天涯浪人 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 20:00

    It depends on your application. The easiest and quickest way is object serialization. You can save an object into to a file and load it again. You would do this with the object that holds your table data. There are a lot of tutorials available for that.

    You can extend the concept of serialization by transforming your object in something human readable first (like XML or JSON) and save it as a file then. This has the benefit that you can use the exported data in something other than a Java program. A framework for marshalling to XML is JAXB. Also a lot of tutorials on that.

    Finally you could use a SQL database. A database would be the most performant alternative. A nice framework for persistence in SQL ins Hibernate. It is mostly used for bigger business applications that need a fast data storage backend. Of cause you have to run an SQL server for that one. Again a lot of tutorials available.

    I guess for your case the first alternative would be the best because its quick and easy. SQL would be a little overkill ;-)

提交回复
热议问题