Quick revision
The short answer
Properties.load reads key-value lines, where the key ends at the first unescaped =, : or whitespace, and lines starting with # or ! are comments. load(InputStream) decodes bytes as ISO-8859-1, so other characters need \u escapes unless we use load(Reader) with a UTF-8 reader. The backslash is an escape character, so Windows paths break, a trailing backslash joins lines, leading whitespace before a value is dropped while trailing whitespace is kept, and because Properties extends Hashtable<Object,Object>, non-string values can sneak in.
What to remember
In this answer, we saw how Properties parses each line into a key and a value with =, : or whitespace as separators and # or ! comments. load(InputStream) reads ISO-8859-1 and needs \u escapes, load(Reader) reads whatever charset we give it, and ResourceBundle reads UTF-8 since Java 9 with an ISO-8859-1 fallback. We saw how backslashes turn Windows paths into tabs and newlines, how a trailing backslash continues a line, how trailing whitespace stays in values, and why setProperty and getProperty are the safe way to use a class that is really a Hashtable of objects.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Properties.load reads key-value lines, where the key ends at the first unescaped =, : or whitespace, and lines starting with # or ! are comments. load(InputStream) decodes bytes as ISO-8859-1, so other characters need \u escapes unless we use load(Reader) with a UTF-8 reader. The backslash is an escape character, so Windows paths break, a trailing backslash joins lines, leading whitespace before a value is dropped while trailing whitespace is kept, and because Properties extends Hashtable<Object,Object>, non-string values can sneak in.
Why this question is asked
Properties files are everywhere in Java: application configuration, message bundles for translations, build tool settings, test fixtures. The format looks so simple that people rarely read its rules, and then lose an afternoon to a value with an invisible trailing space or a path whose backslashes vanished. Interviewers ask about it because the pitfalls are concrete and show whether we understand how the format is parsed. In this answer, we will recap the format, see how load decodes characters with each overload, look at what ResourceBundle does differently, work through escaping and whitespace pitfalls with their results, and see why Properties being a Hashtable still matters.
1A Quick Recap of the Format
A properties file is a list of entries, one per logical line. The key starts at the first non-whitespace character and ends at the first unescaped =, : or whitespace; the separator and any whitespace around it are skipped, and the rest of the line is the value. Lines whose first non-whitespace character is # or ! are comments, and blank lines are ignored.
All three separators work, so the three entries are db.url, db.user and greeting. Notice that greeting Hello world gives the key greeting and the value Hello world, because a space ends the key. A key containing a space must escape it, as in my\ key=value.
2How load Decodes Characters
There are two overloads, and they decode differently. load(InputStream) treats the bytes as ISO-8859-1, Latin-1, where every byte is one character. That covers English and Western European letters, but anything outside it, such as Cyrillic, Chinese or emoji, must be written as a Unicode escape. load(Reader) uses whatever charset the Reader was created with, so a UTF-8 reader reads UTF-8 directly.
So the rule is: when we control the code, load through a UTF-8 Reader. The \uXXXX escapes work with both overloads, which is why older projects escaped every non-ASCII character, sometimes with the native2ascii tool. Note also that store(OutputStream) writes ISO-8859-1 and escapes everything else, while store(Writer) writes in the writer's charset.
3What ResourceBundle Does Differently
ResourceBundle, which loads translated messages such as messages_de.properties, has its own rule. Since Java 9, PropertyResourceBundle reads properties files as UTF-8 by default. If the file is not valid UTF-8, it falls back to ISO-8859-1, so old Latin-1 bundles keep working. The system property java.util.PropertyResourceBundle.encoding can force one of the two.
But there is a catch: that fallback only happens when the bytes are invalid as UTF-8. A Latin-1 file that happens to contain only ASCII is read the same either way, and a file mixing both encodings can produce surprising results. Saving every properties file as UTF-8 removes the ambiguity.
| API | Charset | Non-ASCII without escapes |
|---|---|---|
Properties.load(InputStream) | ISO-8859-1 | broken unless written as \uXXXX |
Properties.load(Reader) | the Reader's charset | fine with a UTF-8 Reader |
ResourceBundle (Java 9+) | UTF-8, falls back to ISO-8859-1 | fine if the file is UTF-8 |
4Escaping Pitfalls: Backslashes and Line Continuation
The backslash starts an escape sequence, just as in Java strings, and this is where Windows paths go wrong. \t becomes a tab, \n a newline, \r a carriage return, \uXXXX a Unicode character, and a backslash before any other character is simply dropped.
A backslash at the very end of a line means the entry continues on the next line, and the leading whitespace of the continuation line is dropped, which is how list became one,two,three. That is handy for long values, but an accidental trailing backslash, for example at the end of a Windows path, silently swallows the next line into the value, and that next entry disappears.
5Whitespace Pitfalls
Whitespace is treated asymmetrically. Whitespace before the key, and between the separator and the value, is skipped. Whitespace at the end of the value is kept. Editors rarely show it, so a value can look right and still be wrong.
So when reading numbers or flags, trim the value, or better, use a configuration layer such as Spring Boot's binding, which converts and validates types. A trailing space in a password or a host name causes errors that are especially hard to see in logs.
6Properties Is a Hashtable of Objects
For historical reasons Properties extends Hashtable<Object,Object>. So put accepts any object, but getProperty only returns String values; for anything else it returns null, and store throws ClassCastException when it meets a non-string.
Using setProperty and getProperty only keeps Properties honest. Properties also supports default values through a defaults Properties object passed to its constructor, and getProperty(key, default) for a single fallback value.
7Follow-up questions
Why does Properties use ISO-8859-1 at all?
The class dates from Java 1.0, when ISO-8859-1 with Unicode escapes was a simple, platform independent choice. Changing load(InputStream) later would have broken existing files, so the Reader overload was added in Java 6 instead.
Does Spring Boot read application.properties with the same rules?
It follows the same escaping and whitespace syntax, so the backslash and trailing space pitfalls apply. How it decodes non-ASCII characters has changed between versions, so check your version's documentation, or use YAML or escapes if you need non-ASCII values.
How do you keep insertion order when writing properties?
Properties is a hash table, so store writes entries in no guaranteed order. For human-edited files that should stay stable, generate them from a sorted map or a template rather than calling store.
8Conclusion
In this answer, we saw how Properties parses each line into a key and a value with =, : or whitespace as separators and # or ! comments. load(InputStream) reads ISO-8859-1 and needs \u escapes, load(Reader) reads whatever charset we give it, and ResourceBundle reads UTF-8 since Java 9 with an ISO-8859-1 fallback. We saw how backslashes turn Windows paths into tabs and newlines, how a trailing backslash continues a line, how trailing whitespace stays in values, and why setProperty and getProperty are the safe way to use a class that is really a Hashtable of objects.
Open with
Properties.load reads one logical line per entry: the key runs until the first unescaped equals sign, colon or whitespace, the separator and whitespace after it are skipped, and the rest is the value; lines starting with hash or exclamation mark are comments.
Then, if they want more
The encoding depends on the overload. load with an InputStream decodes ISO-8859-1, so anything outside Latin-1 has to be written as a backslash-u escape, while load with a Reader uses the reader's charset, so I always load through a UTF-8 reader.
ResourceBundle is different: since Java 9 it reads properties files as UTF-8 and falls back to ISO-8859-1 if the file is not valid UTF-8. The pitfalls I watch for are escaping and whitespace. Backslash is an escape character, so C:\temp\new turns into a tab and a newline; Windows paths need double backslashes or forward slashes.
A backslash at the end of a line continues the value onto the next line, which can swallow the next entry by accident. Leading whitespace before the value is dropped, but trailing whitespace is kept, so timeout=30 with a trailing space fails Integer.parseInt.
Finally, Properties extends Hashtable of Object to Object, so you can put an Integer, but getProperty then returns null and store fails, so I only use setProperty and getProperty.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 9, Java 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does java.util.Properties read a .properties file, and what pitfalls exist with...": https://scrivio-interview-library.netlify.app/java/io-and-nio/2656067d6a/