Package org.kissweb
Class IniFile
java.lang.Object
org.kissweb.IniFile
Class to deal with ini files. These are text-based property files broken into sections. Each section may have any number of key/value pairs. You can also dispense with the sections if you only have one.
The file can also have blank and comment lines. Comment lines start with a semicolon, colon, hash, dash, or astrix. Keys and values may be quoted with either single or double quotes.
This class is thread-safe.
Files look as follows:
The file can also have blank and comment lines. Comment lines start with a semicolon, colon, hash, dash, or astrix. Keys and values may be quoted with either single or double quotes.
This class is thread-safe.
Files look as follows:
[section]
key = value
key2 = value2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the string value of a key from the ini file from thenullsection.Returns the value of a key from a specified section in the ini file.booleangetBoolean(String key) Retrieves the Boolean value of a key from the ini file from thenullsection.booleangetBoolean(String section, String key) Retrieves the boolean value of a key from a specified section in the ini file.Retrieves the Character value of a key from the ini file from thenullsection.Retrieves the first character of a key from a specified section in the ini file.intgetDateInt(String key) Retrieves the integer value representing a date as YYYYMMDD of a key from the ini file from thenullsection.intgetDateInt(String section, String key) Retrieves the integer value of a date key from a specified section in the ini file.Retrieves the Double value of a key from the ini file from thenullsection.Retrieves the double value of a key from a specified section in the ini file.Returns the filename of the ini file.Retrieves the Integer value of a key from the ini file from thenullsection.Retrieves the integer value of a key from a specified section in the ini file.intgetTimeInt(String key) Retrieves the integer value representing a date as HHMM of a key from the ini file from thenullsection.intgetTimeInt(String section, String key) Retrieves the integer value of a time key from a specified section in the ini file.static IniFileLoad an ini file from a disk file.static voidThis test program can be run from the command-line as follows:
java -cp work/Kiss.jar org.kissweb.IniFilevoidPuts a key-value pair into the ini file in thenullsection.voidPuts a key-value pair into the ini file in thenullsection.voidPuts a key-value pair into the ini file in thenullsection.voidPuts a key-value pair into the ini file in thenullsection.voidPuts a key-value pair into the ini file in thenullsection.voidPuts a key-value pair into the ini file in thenullsection.voidPuts a key-value pair into a specified section of the ini file.voidPuts a key-value pair into a specified section of the ini file.voidPuts a key-value pair into a specified section of the ini file.voidPuts a key-value pair into a specified section of the ini file.voidPuts a key-value pair into a specified section of the ini file.voidPuts a key-value pair into a specified section of the ini file.voidPuts a key-value pair into a specified section of the ini file.voidPuts a key-value pair into the ini file in thenullsection.voidRemoves the key-value pair associated with the given key from the ini file in thenullsection.voidRemoves the specified key/value pair from the specified section of the ini file.voidremoveValue(String key) Removes the value associated with the given key from the ini file in thenullsection.voidremoveValue(String section, String key) Removes the specified key from the specified section of the ini file.voidsave()Save the in-memory ini file to file it was read from.voidSave the in-memory ini file to the specified file.
-
Constructor Details
-
IniFile
public IniFile()Create a new ini file in memory. If it is to be saved, the file name to be used can be specified later. -
IniFile
Create a new ini file in memory that will be saved to the specified file.- Parameters:
fname-
-
-
Method Details
-
load
Load an ini file from a disk file.- Parameters:
fname-- Returns:
- Throws:
IOException
-
getFilename
Returns the filename of the ini file. -
get
Returns the value of a key from a specified section in the ini file.- Parameters:
section- the section to search for the keykey- the key to search for- Returns:
- the value of the key if found, null otherwise
-
getInt
Retrieves the integer value of a key from a specified section in the ini file.- Parameters:
section- the section to search for the keykey- the key to search for- Returns:
- the integer value of the key if found, null otherwise
-
getChar
Retrieves the first character of a key from a specified section in the ini file.- Parameters:
section- the section to search for the keykey- the key to search for- Returns:
- the first character of the key if found, null otherwise
-
getBoolean
Retrieves the boolean value of a key from a specified section in the ini file.- Parameters:
section- the section to search for the keykey- the key to search for- Returns:
- true if the value starts with 't', '1', or 'y', false otherwise
-
getDouble
Retrieves the double value of a key from a specified section in the ini file.- Parameters:
section- the section to search for the keykey- the key to search for- Returns:
- the double value of the key if found, null otherwise
-
getDateInt
Retrieves the integer value of a date key from a specified section in the ini file.- Parameters:
section- the section to search for the keykey- the key to search for- Returns:
- the integer value of the key if found (YYYYMMDD), 0 otherwise
-
getTimeInt
Retrieves the integer value of a time key from a specified section in the ini file.- Parameters:
section- the section to search for the keykey- the key to search for- Returns:
- the integer value of the key if found (HHMM), 0 otherwise
-
put
Puts a key-value pair into a specified section of the ini file.- Parameters:
section- the section to put the key-value pair intokey- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into a specified section of the ini file.- Parameters:
section- the section to put the key-value pair intokey- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into a specified section of the ini file.- Parameters:
section- the section to put the key-value pair intokey- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into a specified section of the ini file.- Parameters:
section- the section to put the key-value pair intokey- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into a specified section of the ini file.- Parameters:
section- the section to put the key-value pair intokey- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into a specified section of the ini file.- Parameters:
section- the section to put the key-value pair intokey- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into a specified section of the ini file.- Parameters:
section- the section to put the key-value pair intokey- the key to put into the sectionvalue- the value to put into the section
-
save
Save the in-memory ini file to the specified file.- Parameters:
fname-- Throws:
IOException
-
save
Save the in-memory ini file to file it was read from.- Throws:
IOException
-
removeValue
Removes the specified key from the specified section of the ini file.- Parameters:
section- the section to remove the key fromkey- the key to remove
-
removeKey
Removes the specified key/value pair from the specified section of the ini file.- Parameters:
section- the section to remove the key fromkey- the key to remove
-
get
Retrieves the string value of a key from the ini file from thenullsection.- Parameters:
key- the key to search for- Returns:
- the value of the key if found, null otherwise
-
getInt
Retrieves the Integer value of a key from the ini file from thenullsection.- Parameters:
key- the key to search for- Returns:
- the value of the key if found, null otherwise
-
getChar
Retrieves the Character value of a key from the ini file from thenullsection.- Parameters:
key- the key to search for- Returns:
- the value of the key if found, null otherwise
-
getBoolean
Retrieves the Boolean value of a key from the ini file from thenullsection.- Parameters:
key- the key to search for- Returns:
- the value of the key if found, false otherwise
-
getDouble
Retrieves the Double value of a key from the ini file from thenullsection.- Parameters:
key- the key to search for- Returns:
- the value of the key if found, null otherwise
-
getDateInt
Retrieves the integer value representing a date as YYYYMMDD of a key from the ini file from thenullsection.- Parameters:
key- the key to search for- Returns:
- the value of the key if found, 0 otherwise
-
getTimeInt
Retrieves the integer value representing a date as HHMM of a key from the ini file from thenullsection.- Parameters:
key- the key to search for- Returns:
- the value of the key if found, 0 otherwise
-
put
Puts a key-value pair into the ini file in thenullsection.- Parameters:
key- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into the ini file in thenullsection.- Parameters:
key- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into the ini file in thenullsection.- Parameters:
key- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into the ini file in thenullsection.- Parameters:
key- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into the ini file in thenullsection.- Parameters:
key- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into the ini file in thenullsection.- Parameters:
key- the key to put into the sectionvalue- the value to put into the section
-
put
Puts a key-value pair into the ini file in thenullsection.- Parameters:
key- the key to put into the sectionvalue- the value to put into the section
-
removeValue
Removes the value associated with the given key from the ini file in thenullsection.- Parameters:
key- the key to remove the value for
-
removeKey
Removes the key-value pair associated with the given key from the ini file in thenullsection.- Parameters:
key- the key to remove the value for
-
main
This test program can be run from the command-line as follows:
java -cp work/Kiss.jar org.kissweb.IniFile- Parameters:
args-- Throws:
IOException
-