How can I get the number of times a program has previously run in java without keeping a file and tallying. Is there a Application class or something in java to check the count
You could use the preferences API. This eliminates the need for you to do the file i/o. You will still need to read the preference value, increment it, and then store the new value.
On Windows, the preferences API uses the registry. On Unix, the preferences API uses the file system as the backing store (but this is hidden from you as a developer).
You can get/store preferences for either the system, or for an individual user. (It's not clear if you want to know how many times a user ran the program, or how many times anyone on said computer ran the program). Look for Preferences.systemNodeForPackage()
and Preferences.userNodeForPackage()
in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With