ここには簡単なResourceBundleメッセージファイル
hello = "Hi \n \n Good Morning \n \n thanks"
リソースバンドルキー “hello”を取得すると、次のように結果が期待されます
Hi Good Morning thanks
残念ながら、Javaはこの方法では動作しません。 “String”はデフォルトで\ nを新しい行に変換しません。リソースバンドルから「hello」を直接取得すると、次の結果が得られます。これは私たちが望むものではありません….
Hi \n \n Good Morning \n \n thanks
解決策
私たちがする必要があるのは、 “\ n”をJavaの新しい行に変換することです。
String org.apache.commons.lang.StringEscapeUtils.unescapeJava(String
str)Unescapes any Java literals found in the String. For example, it will
turn a sequence of ‘\’ and ‘n’ into a newline character, unless the ‘\’
is preceded by another ‘\’.Parameters:
str the String to unescape, may be null