Creating .INI Classes In Java
by Mark Meyer


Example 1:

; this is a comment
[MGDSFAXGEN]
UserName
SpoolFileName=c:\winnt\temp\zetafax.spl
# this is also a comment
InstructFileLocation=INSTRUCT
FaxFormat=FINE
TopMargin=0.01
BottomMargin=0.01
LeftMargin=0.01
RightMargin=0.01
ReportPath=c:\prodmgds\

Example 2:

TOKEN :
{
| <USCORE: "_"
| <PERIOD: "."
| <HYPHEN: "-"
| <EQUALS: "="
| <LBRACK: "["
| <RBRACK: "]"


Figure 3: C++ style comments in an ini file

// NAME
//   opctrnm.ini - Counter Loading file
// DESCRIPTION
//   File that contains description of counters 
//   to be loaded into the registry.
//RELATED DOCUMENTS


Listing One
// constructor
public IniFile( String filePathName, boolean caseOn ) throws
IOException {
  this.setCaseOn(caseOn);
  this.setLineNumberRead(filePathName);
}
// turn case sensitivity off
IniFile inf = new IniFile(args[0],false);

Listing Two
// load the contents of the file passed in to the contructor
inf.loadFromFile();

Listing Three
 // create IniFile object from mark.ini
IniFile inf = new IniFile("c:\\mark.ini",false);
inf.loadFromFile();
// add a section in memory
IniSection sect = inf.addSection("fruit");
// add a key+value pair under the "fruit" section
sect.setValue("banana","yellow");
// write contents of memory out to mega.ini
inf.setFileName("c:\\mega.ini");
inf.flushToFile();

Listing Four
currentSection = new IniSection( name, this.getCaseOn() );
public void setValue (String key, String value){
  String s;
  if (getCaseOn()){
    s = key.toUpperCase();
  }
  else{
    s = key;
  }
  if (!this.hasKey(key)){
    _map.put( s, value );
  }
}

Listing Five
1 # comment 1
2 <white space here
3 # comment 2
4 <white space here
5 [MyFirstSection]
6 <white space here
7 ; comment = 3 very bogus
8 banana = yellow
9 apple = red
10 [MyNextSection]

Listing Six

private HashMap _commentTable = new HashMap();
public void addComment(String name, String value){
   _commentTable.put(name,value);
}

Listing Seven
IniFile inf = new IniFile("c:\mark.ini",false);
inf.addComment("POUND","#
");
inf.addComment("SEMICOLON",";");
inf.addComment("DOUBLESLASH","//");

Listing Eight
public void setValue (String key, String
ue){
  String s;
  if (getCaseOn()){
     s = key.toUpperCase();
  }
  else{
    s = key;
  }
  if (!this.hasKey(key)){
    _map.put( s, value );
  }
}







3


