-3

I'm doing a java GUI Project, in which I'm giving a SETTING Feature in which user can able to change the title of window, size, etc,

For example there will be text-box which will receive user input for changing the title... till now all is good...

But what if user restart the application.. Everything will be by default again...

So user have to change the title again..

So I'm trying to store this information.. So that when application will restart.... It will take the tha information and set the values like user wanted..

But i don't know how and where to store these information.... There will be multiple information.. I was thinking to store in file... But how I will retrieve and separate these information......

Just the the way to do it....

If you can give some examples then it will be great :))

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • Wow, slow down. Please improve your question, no one understands it like this. If you need help, go read the [faq]. – MarioDS May 01 '13 at 10:04

2 Answers2

2

Take a look at

Properties. This will require you to provide the file handling I/O to load and save the files.

Preferences API, which uses its own storage mechanism. I tend to find this easier to use then properties as you don't need to worry about the file I/O and its easily instantiated from any where

Java API for XML Processing and Java Architecture for XML Binding which provides XML support if you need a more complex, relational structure then simple properties.

And if none of those meet your particular needs, you could even look at using some kind of Database

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 2
    For an app. launched by [Java Web Start](http://stackoverflow.com/tags/java-web-start/info) see also the [`PersistenceService`](http://pscode.org/jws/api.html#ps). – Andrew Thompson May 01 '13 at 10:27
  • 1
    See also this [example of storing & restoring options](http://stackoverflow.com/a/7778332/418556), though note that `user.home` (or a sub-directory) is a better place to put the properties file. – Andrew Thompson May 01 '13 at 12:39
0

I've had a similar problem. What I did was create a temp directory and put a properties file there.

Getting a temp directory: System.getProperty("java.io.tmpdir") is your temp/ directory. Create a sub-directory for your application.

Use java.util.Properties to easily store and open what you need. Don't forget to update that file whenever anything changes. I've used it to store the window state (maximized / normal), size, position, last location of File -> Open dialog, etc.

iluxa
  • 6,941
  • 18
  • 36
  • 1
    I'd avoid io.temp, personally, and user "user.home", storing the values within an appropriate directory (under AppData for Windows for example) – MadProgrammer May 01 '13 at 10:09