I am building a database and I want to be able to store a user input filepath and have it available as a variable even after the application is closed and restarted to prevent retyping the path with each launch.
Asked
Active
Viewed 50 times
1
-
2Store it somewhere: file, database, cookie, etc. – PM 77-1 Jan 06 '17 at 21:09
-
You may want to look into `java.util.prefs.Preferences`. – Ole V.V. Jan 06 '17 at 21:38
-
@OleV.V. I'm not sure that you quite understood what I was looking for as that seems to be more for general application settings rather than a specific variable value. – Bman76 Jan 07 '17 at 03:30
1 Answers
2
Use a file where you store the information in the form :
key=value
For example :
filepath=C://myFolder
And use Properties to retrieve the information from the file.
https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html

davidxxx
- 125,838
- 23
- 214
- 215
-
Now the only thing that needs to be done is locating that file... If you store it in a jar, you'll have problems writing to it; if you store it outside, you'll probably face difficulties locating it... – fabian Jan 06 '17 at 22:24
-
Storing it outside should be the privileged solution in rich-client applications. Generally, the file is defined in a path relative to the directory where the application is copied/installed but it may also be the user directory. – davidxxx Jan 06 '17 at 22:28
-
Thanks for the assistance I actually forgot about the properties class to store info. – Bman76 Jan 07 '17 at 03:21
-
1