To preface, file reading is definitely a thing in Java.
ex)
InputStream in = new FileInputStream("inputFile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String currentLine;
try {
while((currentLine = br.readLine()) != null)
{
// output the current line
System.out.println(currentLine);
}
} catch(Exception e) {
System.out.println(e);
} finally {
in.close();
}
To read the entire file in one go :
InputStream in = new FileInputStream("foo.txt");
String fileContents;
try {
fileContents = IOUtils.toString(inputStream);
} finally {
in.close();
}
Reading a file can be done using a Reader or InputStream. Each of these are interfaces, meaning they are a contract that describes how anything considered a Reader or InputStream must function. For the Reader or InputStream to function it must be implemented in some specific manner.
In the above cases, in is declared on the left as a InputStream, and the specific type of InputStream (how it is implemented) is declared on the right.
Note that the implementations of these interfaces are also listed in there doc.
Another key thing to note is the use of in.close();. A finally statement is used to ensure a piece of code is executed even if the application errors out. This is done to ensure the file handle is released.
Storing Configuration Properties
Configuration properties are generally simple key value pairs, such as :
key1=value1
key2=value2
Though in some circumstances it may be beneficial to store more complex data structures such as lists or dictionaries / maps. For this a better serialization format can be used. A format generally better for storing data like this is YAML, and an easy subset of YAML to begin using, JSON.
JSON is a structure for expressing Javascript objects, which are simple dictionaries / maps of keys to values. Value may be strings, numbers, dictionaries, and lists. A dictionary or list may contain values. This allows for data considered more complex than a simple key value store to be expressed.