How to save application options before exit?

前端 未结 4 2002
一个人的身影
一个人的身影 2020-12-13 05:01

I have made an application and i need to save some options before exit.(something like window dimension, ..., that will be written in a file.)

The main frame has set

4条回答
  •  一个人的身影
    2020-12-13 05:38

    May be the following will help.

    1. First u need to read your property file. See doc

      Properties properties = new Properties();
      try {
        properties.load(new FileInputStream("filename.properties"));
      } catch (IOException e) {
        System.err.println("Ooops!");
      }
      
    2. Second add event handler to your window, which will save your data in property file.All that you need to save just put in properties instance and store it on exit

       addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
          try {
           properties.store(new FileOutputStream("filename.properties"), null);
          } catch (IOException e) {
          }
        }
      });
      

    That's all, if I'd understood you correct)

提交回复
热议问题