Obviously enough, I want to avoid hardcoding paths and such into my application, and as a result, I\'d like to make a settings file that will store simple things like string
I would suggest to you (and to anyone who may be reading this) that you consider the Reflection API. Be warned though that it is generally considered bad practice to use reflection in production code.
You could define a class with all of the different fields in the settings file:
public class Settings {
public String name;
public int age;
public String profilePicturePath;
public double rating;
}
And your settings file could look something like this:
name=John
age=30
profilePicturePath=images/john.png
rating=8.5
It is important that the field names in the settings file match the field names in the class. If they don't; you could always write a function to convert them (e.g., a function to convert a settings file field name with spaces ("Profile Picture Path") to a camelCase name ("profilePicturePath")).
Now you would iterate over all of the strings in the settings file and extract the field name and value from each of them, both as strings. I'm not going to explain how to use reflection here, but the idea is that for each field in the settings file you would use reflection to locate the field in the Settings class with the same name and check it's type. You would then apply the appropriate conversion method to the value from the settings file and use reflection to set the field in a Settings object to the converted value.
Although this approach uses reflection, which is frowned upon, it's beauty lies in the fact that it can be generalized for any field; you don't have to handle each field individually. If you want to add another setting, all you need to do is add two lines: one to your settings file and one to your Settings class. You can also expand this to load enums and perhaps even instances of other classes!