You have already loaded property file. After some time, someone comes and make changes in your property file.
But your application still uses the old value of the property. Err... problem right??
Needed this new value in your application, right?
Solution:-
Try out PropertyChangeAdapter to get changed property value.
Instead of loading this property file, just create instance of PropertyChangeAdapter class and using getProperty(), getOldValue(), getNewValue() methods you can still get all the old and new values of property file.
isPropertyChanged() will tell you whether property is changed or not.
getChangedProperties() will give you all Changed properties in
To Download
http://jlisteners.sourceforge.net/
Ready to Go
ü Download JListerner.jar.
ü Put this JAR file in your classpath.
ü Download PropertyListenerDemo java file.
ü Download conf.properties file.
ü Run this PropertyListenerDemo java program.
PropertyChangeListener Examples:-
Create an object of ExcelAdapter class
// provide filepath and also interval (in milliseconds) to track changes
PropertyChangeAdapter objProp = new PropertyChangeAdapter("conf.
//get the property using
objProp.getProperty("message")
// to check property value is changes
l_objProp.isPropertyChanged("
// to get new value of property
l_objProp.getNewValue("
// to get old value of property
l_objProp.getOldValue("
// to get list of changed properties
l_objProp.
Another Example:-
// first command line argument is filepath and 2nd is interval in milliseconds
Run PropertyListenerDemo program using
java -cp JListerner.jar;.; PropertyListenerDemo mypropertyfile.properties 1000
Hold on... this API has other listeners too... :)...
FileChangeListener / DirectoryChangeListener Examples:-
Create an object of ExcelAdapter class
// provide filepath and also interval (in milliseconds) to track changes
FileChangeAdapter objFileChangeListner = new FileChangeAdapter("D:\\myDir", 1000);
//check directory content is changed
objFileChangeListner.
// to get changed file object
l_ objFileChangeListner.
// to get all changed file objects
l_ objFileChangeListner.
// to get all file objects present in directory (In case directory path provided) or file object for one specific file
l_ objFileChangeListner.
Another Example:-
ü Download FileListenerDemo java file.
// first command line argument is filepath/directorypath and 2nd is interval in milliseconds
Run PropertyListenerDemo program using
java -cp JListerner.jar;.; FileListenerDemo D:\\src 1000
There are other listeners which will be added periodically.
Thursday, March 19, 2009
Property & File/Directory Change Listener
Subscribe to:
Posts (Atom)