Package com.pnfsoftware.jeb.util.base
Class IniFileEditor
java.lang.Object
com.pnfsoftware.jeb.util.base.IniFileEditor
A reader-and-writer for
ini
configuration files.
Example of a valid ini file:
[section1] foo bar [section2] x y [section3] [section4] z
-
Constructor Summary
ConstructorsConstructorDescriptionIniFileEditor
(File file) IniFileEditor
(File file, Character commentChar) IniFileEditor
(String str) IniFileEditor
(String str, Character commentChar) -
Method Summary
Modifier and TypeMethodDescriptionRetrieve the optional comment character (full-line comments only).getSectionContents
(String sectionName) Retrieve the contents of a section.getSectionKeyValues
(String sectionName) Retrieve the key-value entries for the provided section.Retrieve the list of sections in the ini file.Retrieve a value.Retrieve a value.Retrieve a value.void
Set a comment character for full-line comments.void
setSectionContents
(String sectionName, List<String> contents) Set the contents of a new section.boolean
Set a value.boolean
Set a value.void
update()
Update the original ini file.void
Write the updated contents to a new ini file.
-
Constructor Details
-
IniFileEditor
- Throws:
IOException
-
IniFileEditor
- Throws:
IOException
-
IniFileEditor
-
IniFileEditor
-
-
Method Details
-
setCommentChar
Set a comment character for full-line comments.- Parameters:
cc
- optional
-
getCommantChar
Retrieve the optional comment character (full-line comments only).- Returns:
-
update
Update the original ini file.- Throws:
IOException
-
write
Write the updated contents to a new ini file.- Parameters:
newFile
-- Throws:
IOException
-
getSectionNames
Retrieve the list of sections in the ini file.- Returns:
-
getSectionContents
Retrieve the contents of a section.- Parameters:
sectionName
-- Returns:
- the section contents, never null; blank entries are not present
-
getSectionKeyValues
Retrieve the key-value entries for the provided section.- Parameters:
sectionName
- case-sensitive section name- Returns:
- a collection, possibly empty
-
setSectionContents
Set the contents of a new section. The section is created if it does not exist.- Parameters:
sectionName
- section name (without bracket)contents
- blank lines are not added
-
getValue
Retrieve a value.- Parameters:
keyName
- key name- Returns:
- the value, null if not found
-
getValue
Retrieve a value.- Parameters:
sectionName
- section namekeyName
- key name- Returns:
- the value, null if not found
-
getValue
Retrieve a value.- Parameters:
sectionName
-keyName
-delimiter
-- Returns:
- the value, null if not found
-
setValue
Set a value.- Parameters:
sectionName
-keyName
-value
-- Returns:
- true if the value was new or a true update; false if the key-value pair already exists
-
setValue
Set a value.- Parameters:
sectionName
-keyName
-value
-delimiter
-- Returns:
- true if the value was new or a true update; false if the key-value pair already exists
-