Byte-preserving Java properties bundle editing
\uXXXX in Java .properties filesThere is no single encoding rule for every API that reads a .properties file.
The API and Java version matter.
Properties.load(InputStream)The byte-stream form of java.util.Properties.load treats each input byte as
ISO-8859-1. Characters outside that range are represented with Unicode escapes
such as \u30AB. The Reader overload instead uses the reader’s character
encoding.
PropertyResourceBundleFor Java 9 and later, a property resource bundle loaded from an input stream is
read as UTF-8 first. If the input is not valid UTF-8, the implementation falls
back to ISO-8859-1 unless configured otherwise. This is separate from the
Properties.load(InputStream) rule.
See the JDK documentation for
Properties
and
PropertyResourceBundle
for the exact behavior.
A UTF-8 byte order mark is the three-byte prefix EF BB BF. It is invisible in
most editors. IntelliJ IDEA can use a BOM as an encoding signal and disables
some manual encoding choices when a file already declares its encoding this
way. IntelliJ normally creates UTF-8 files without a BOM, but its behavior is
configurable in File Encodings.
Do not add or remove a BOM incidentally while changing a value. Whether the runtime accepts it depends on how the file is loaded, and the byte change also creates an unrelated diff.
Pick the convention used by the code that actually loads the file:
Properties.load(InputStream): ISO-8859-1 plus escapes, or change the
code to use an explicitly encoded Reader;ResourceBundle: UTF-8 is supported, subject to its documented
fallback behavior;Then configure the IDE to match and commit that configuration where practical.
BundleSafe detects the
file representation before editing and preserves an existing UTF-8 BOM and
untouched \uXXXX spelling. Its preview shows the raw region that will change.