public class

IniFileEditor

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.base.IniFileEditor

Class Overview

A reader-and-writer for ini configuration files.

Example of a valid ini file:

 [section1]
 
 foo
 
 bar
 
 [section2]
 x
 y
 [section3]
 [section4]
 z
 
 

Summary

Public Constructors
IniFileEditor(File file, Character commentChar)
IniFileEditor(File file)
IniFileEditor(String str, Character commentChar)
IniFileEditor(String str)
Public Methods
Character getCommantChar()
Retrieve the optional comment character (full-line comments only).
List<String> getSectionContents(String sectionName)
Retrieve the contents of a section.
Map<String, String> getSectionKeyValues(String sectionName)
Retrieve the key-value entries for the provided section.
List<String> getSectionNames()
Retrieve the list of sections in the ini file.
String getValue(String sectionName, String keyName, String delimiter)
Retrieve a value.
String getValue(String keyName)
Retrieve a value.
String getValue(String sectionName, String keyName)
Retrieve a value.
void setCommentChar(Character cc)
Set a comment character for full-line comments.
void setSectionContents(String sectionName, List<String> contents)
Set the contents of a new section.
boolean setValue(String sectionName, String keyName, String value)
Set a value.
boolean setValue(String sectionName, String keyName, String value, String delimiter)
Set a value.
void update()
Update the original ini file.
void write(File newFile)
Write the updated contents to a new ini file.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public IniFileEditor (File file, Character commentChar)

Throws
IOException

public IniFileEditor (File file)

Throws
IOException

public IniFileEditor (String str, Character commentChar)

public IniFileEditor (String str)

Public Methods

public Character getCommantChar ()

Retrieve the optional comment character (full-line comments only).

public List<String> getSectionContents (String sectionName)

Retrieve the contents of a section.

Returns
  • the section contents, never null; blank entries are not present

public Map<String, String> getSectionKeyValues (String sectionName)

Retrieve the key-value entries for the provided section.

Parameters
sectionName case-sensitive section name
Returns
  • a collection, possibly empty

public List<String> getSectionNames ()

Retrieve the list of sections in the ini file.

public String getValue (String sectionName, String keyName, String delimiter)

Retrieve a value.

Returns
  • the value, null if not found

public String getValue (String keyName)

Retrieve a value.

Parameters
keyName key name
Returns
  • the value, null if not found

public String getValue (String sectionName, String keyName)

Retrieve a value.

Parameters
sectionName section name
keyName key name
Returns
  • the value, null if not found

public void setCommentChar (Character cc)

Set a comment character for full-line comments.

Parameters
cc optional

public void setSectionContents (String sectionName, List<String> contents)

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

public boolean setValue (String sectionName, String keyName, String value)

Set a value.

Returns
  • true if the value was new or a true update; false if the key-value pair already exists

public boolean setValue (String sectionName, String keyName, String value, String delimiter)

Set a value.

Returns
  • true if the value was new or a true update; false if the key-value pair already exists

public void update ()

Update the original ini file.

Throws
IOException

public void write (File newFile)

Write the updated contents to a new ini file.

Throws
IOException