This directory contains a replica of basic ini file parser java project by Ángel Luis and a minor modifications to that project.
- build app
mvn package- write the file
custom.propertiesin the launcher directory:
USERNAME=defined
# will be overridden by system property with the same name
option1=user:${USERNAME}
FOO=bar
option2=FOO:${FOO}
in the right hand side one can use properties just defined except when the property name collides with predefined ones like USERNAME on WINDOW or HOME on Unix.
you can update the file any time
- run the app, which will simply echo the read values of few options
set debug=false
java -cp target\iniparser-0.3-SNAPSHOT.jar example.test.Testor on Linux
DEBUG=false java -cp target/iniparser-0.3-SNAPSHOT.jar example.test.Test
option1: user:Serguei
option2: FOO:bar
option3: default value for option3
NOTE: the output will be different on Linux where is no USERPROFILE environment variable
- remove the file
custom.propertiesand rerun. Thecustom.propertiesresource will be read
rm -f ./custom.properties
mvn clean package
DEBUG=true java -cp target/iniparser-0.3-SNAPSHOT.jar example.test.Test
Reading properties file: 'C:/developer/sergueik/selenium_java/ini_parser/custom.properties'
Reading properties resource stream: 'custom.properties'
Reading: 'option2' = 'FOO:${FOO}'
getting property: FOO
system property: null
environment property: bar
Reading: 'option1' = 'user:${USERNAME}'
getting property: USERNAME
system property: null
environment property: Serguei
Reading: 'FOO' = 'bar'
Reading: 'USERNAME' = 'defined'
getting property: option1
system property: user:Serguei
option1: user:Serguei
getting property: option2
system property: FOO:bar
option2: FOO:bar
getting property: option3
system property: null
environment property: null
option3: default value for option3
- temporarily remove the file
src/main/resources/custom.propertiesand rebuild and rerun. Thecustom.propertiesresource will be read
rm -f src/main/resources/custom.properties
mvn clean packageDEBUG=true java -cp target/iniparser-0.3-SNAPSHOT.jar example.test.Testdebug: true
fileName: C:/developer/sergueik/selenium_java/ini_parser/custom.properties
Reading properties file: 'C:/developer/sergueik/selenium_java/ini_parser/custom.
properties'
Reading properties resource stream: 'custom.properties'
getting property: option1
system property: null
environment property: null
option1: default value for option1
getting property: option2
system property: null
environment property: null
option2: default value for option2
getting property: option3
system property: null
environment property: null
option3: default value for option3
- C# ini parser project by the same author
- same project embedded in Powershell script with Add-Type
- another Powrshell snippet for processing ini files
- another C# ini parser project
- yet another, somewhat bloated c# project containing complex hierarchy of classes just to deal with the ini file
- default Ruby package for ini files
- blog on how to read and write to INI files easily in Java using
org.ini4j.ini4jjar