laur.tools
Class INIManager
java.lang.Object
|
+--laur.tools.INIManager
- public class INIManager
- extends java.lang.Object
An INIManager object can be used to read and modify the contents of
an initialization file. This class is intended to be used with a
simple format of initialization file consisting of setting-value
pairs separated by an '=', and each appearing on a separate line.
Method Summary |
java.lang.String |
getValue(java.lang.String key)
Obtain the value corresponding to a given key. |
java.util.Iterator |
keys()
Returns an Iterator over all keys. |
static void |
main(java.lang.String[] args)
sample usage and testing |
void |
open(java.lang.String filename)
This method is loading the contents of an INI file in memory. |
void |
save()
This method is saving the settings into the INI file. |
void |
setValue(java.lang.String key,
java.lang.String value)
Set a value for a given key. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
INIManager
public INIManager()
open
public void open(java.lang.String filename)
throws java.io.FileNotFoundException
- This method is loading the contents of an INI file in memory.
- Throws:
java.io.FileNotFoundException
- thrown when the initialization
file is not found. This is just an indication that the file
didn't exist and there is no sense in getting values out of it.
The user can continue by setting default values and then saving
the file by a call to save().
save
public void save()
throws java.io.IOException
- This method is saving the settings into the INI file. We need to
call it only if we have changed settings and we want to save the
changes.
- Throws:
java.io.IOException
- thrown if the initialization file could
not be opened for write. This is signaling some serious error.
getValue
public java.lang.String getValue(java.lang.String key)
- Obtain the value corresponding to a given key.
- Parameters:
key
- the key whose value we want to get.- Returns:
- the value corresponding to the given key, or null if no
such key.
setValue
public void setValue(java.lang.String key,
java.lang.String value)
- Set a value for a given key.
- Parameters:
key
- the key whose value we want to set.value
- the value that we want to set.
keys
public java.util.Iterator keys()
- Returns an Iterator over all keys.
- Returns:
- an Iterator over all keys.
main
public static void main(java.lang.String[] args)
- sample usage and testing