Home » Archive

Articles tagged with: java loading textfile configuration

Java Codes »

[20 Feb 2009 | No Comment | 79 views]

The Arrays class can be used to sort an array of either reference types or primitive types, but the Arrays class does have an overloaded sort method that can sort an array in any way we choose. That overloaded variant of the sort method can only take reference types, and it has an additional parameter which is of type Comparator. This is the parameter that tells how we want the array sorted. In the example below we call the static method reverseOrder on the Collections class. It returns a Comparator …

Java Codes »

[13 Feb 2009 | No Comment | 143 views]

Loading parameters into a program is easily handled in Java through the Properties class.
The only thing that has to be done is to create an instance of the Properties class and one instance of
FileInputStream class that points to the configuration file.
The actual loading of the parameters are done through the method load() on the Properties object.
In the example below parameters are read from the configuration file and then printed out.
This is what the sample configuration file looks like:

# System configuration
# Comments will automatically be excluded by the program.parameter1=value1
parameter2=value2

 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import …