Java Properties file FAQ: Can you show me how to read a Java Properties file?
Here is a snippet of Java source code that shows how to read a Java Properties file named
Pizza.properties. It reads in two properties named
Properties properties = new Properties(); FileInputStream in = new FileInputStream("Pizza.properties"); properties.load(in); in.close(); String crust = properties.getProperty("CRUST"); String toppings = properties.getProperty("TOPPINGS");
This simple coding approach makes using Java Properties files very convenient to use for storing your application properties.
What a properties file looks like
Also, if it helps to know it, a Properties file has a collection of name/value pairs, separated by an equal sign, and comments allowed, like this:
# the user's name username=al # the user's zip code zip_code=99676
There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.