|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.huguesjohnson.IniFile
public class IniFile
Reads/writes old-school Windows style .ini files.
Recommended usage:
private void readSavedSettings(){
IniFile iniFile=new IniFile(this.settingsPath+File.separator+"YourAppName.ini");
try{
iniFile.read();
} catch(IOException x){
//something bad happened
}
final String defaultString=new String("YourDefaultValue");
String property1=new String(iniFile.getProperty("YourAppProperty",defaultString));
String property2=new String(iniFile.getProperty("AnotherAppProperty",defaultString));
//and so on..
}
}
private void saveSettings(){
IniFile iniFile=new IniFile(this.settingsPath+File.separator+"YourAppName.ini");
if(iniFile!=null){
iniFile.setProperty("YourAppProperty",this.someVariable);
iniFile.setProperty("AnotherAppProperty",this.anotherVariable);
iniFile.save("some header");
}
}
| Constructor Summary | |
|---|---|
IniFile(java.lang.String fileName)
Create a new instance of IniFile. |
|
| Method Summary | |
|---|---|
void |
clear()
Clears out all loaded properties, does not modify the underlying file. |
boolean |
getProperty(java.lang.String name,
boolean defaultValue)
Returns a property from memory. |
byte |
getProperty(java.lang.String name,
byte defaultValue)
Returns a property from memory. |
char |
getProperty(java.lang.String name,
char defaultValue)
Returns a property from memory. |
double |
getProperty(java.lang.String name,
double defaultValue)
Returns a property from memory. |
float |
getProperty(java.lang.String name,
float defaultValue)
Returns a property from memory. |
int |
getProperty(java.lang.String name,
int defaultValue)
Returns a property from memory. |
long |
getProperty(java.lang.String name,
long defaultValue)
Returns a property from memory. |
java.lang.String |
getProperty(java.lang.String name,
java.lang.String defaultValue)
Returns a property from memory. |
void |
read()
Reads the file specified in the constuctor. |
void |
save(java.lang.String header)
Saves settings to file specified in the constuctor. |
void |
setProperty(java.lang.String name,
boolean value)
Sets a property in memory - use save() to write all properties back to the file. |
void |
setProperty(java.lang.String name,
byte value)
Sets a property in memory - use save() to write all properties back to the file. |
void |
setProperty(java.lang.String name,
char value)
Sets a property in memory - use save() to write all properties back to the file. |
void |
setProperty(java.lang.String name,
double value)
Sets a property in memory - use save() to write all properties back to the file. |
void |
setProperty(java.lang.String name,
float value)
Sets a property in memory - use save() to write all properties back to the file. |
void |
setProperty(java.lang.String name,
int value)
Sets a property in memory - use save() to write all properties back to the file. |
void |
setProperty(java.lang.String name,
long value)
Sets a property in memory - use save() to write all properties back to the file. |
void |
setProperty(java.lang.String name,
java.lang.String value)
Sets a property in memory - use save() to write all properties back to the file. |
java.lang.String |
toString()
Returns the path to the file specified in the constructor and all properties currently in memory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public IniFile(java.lang.String fileName)
read() method to load the contents from the file.
fileName - Full path of ini file to read/write.| Method Detail |
|---|
public void read()
throws java.io.IOException
java.io.IOException - Exception thrown if the file does not exist or another I/O error occurs.
public void save(java.lang.String header)
throws java.io.IOException
header - New header for ini file.
java.io.IOException - Exception thrown if an I/O error occurs.public void clear()
public void setProperty(java.lang.String name,
java.lang.String value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public void setProperty(java.lang.String name,
int value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public void setProperty(java.lang.String name,
boolean value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public void setProperty(java.lang.String name,
long value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public void setProperty(java.lang.String name,
float value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public void setProperty(java.lang.String name,
double value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public void setProperty(java.lang.String name,
char value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public void setProperty(java.lang.String name,
byte value)
save() to write all properties back to the file.
name - The name (key) of the setting.value - The value of the setting.
public java.lang.String getProperty(java.lang.String name,
java.lang.String defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public int getProperty(java.lang.String name,
int defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public boolean getProperty(java.lang.String name,
boolean defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public double getProperty(java.lang.String name,
double defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public byte getProperty(java.lang.String name,
byte defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public long getProperty(java.lang.String name,
long defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public float getProperty(java.lang.String name,
float defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public char getProperty(java.lang.String name,
char defaultValue)
name - The name (key) of the property to retrieve.defaultValue - The value to return if property is not found.
public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||