Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count No of times Program has been executed

Tags:

java

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

like image 355
user1381151 Avatar asked May 08 '12 04:05

user1381151


1 Answers

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.

like image 118
Greg Kopff Avatar answered Sep 29 '22 11:09

Greg Kopff