ドイツ語の文字を16進値(00E4)にマップするプロパティファイルがあります。私は "iso-8859-1"でこのファイルをエンコードする必要がありました。ドイツ語の文字を表示する唯一の方法でした。私がしようとしているのは、ドイツ語を使い、文字列のどこにでもこれらの文字が現れているかどうか、そしてその値を16進形式に置き換えるかどうかを調べることです。例えば、ドイツのチャートを\u00E4
に置き換えてください。プロパティファイルに " u"を書き込まないJava
コードは文字の罰金に置き換えられますが、1つのバックラッシュの代わりに、私は\\u00E4
のようになります。私はコードで"\\u"
を使用して、\u
を試してみるのを見ることができますが、それは起こりません。私がここで間違っているところのアイデア?
private void createPropertiesMaps(String result) throws FileNotFoundException, IOException
{
Properties importProps = new Properties();
Properties encodeProps = new Properties();
// This props file contains a map of german strings
importProps.load(new InputStreamReader(new FileInputStream(new File(result)), "iso-8859-1"));
// This props file contains the german character mappings.
encodeProps.load(new InputStreamReader(
new FileInputStream(new File("encoding.properties")),
"iso-8859-1"));
// Loop through the german characters
encodeProps.forEach((k, v) ->
{
importProps.forEach((key, val) ->
{
String str = (String) val;
// Find the index of the character if it exists.
int index = str.indexOf((String) k);
if (index != -1)
{
// create new string, replacing the german character
String newStr = str.substring(0, index) + "\\u" + v + str.substring(index + 1);
// set the new property value
importProps.setProperty((String) key, newStr);
if (hasUpdated == false)
{
hasUpdated = true;
}
}
});
});
if (hasUpdated == true)
{
// Write new file
writeNewPropertiesFile(importProps);
}
}
private void writeNewPropertiesFile(Properties importProps) throws IOException
{
File file = new File("import_test.properties");
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
importProps.store(writer, "Unicode Translations");
writer.close();
}
「2つのようになっています。\ u00E4」それはタイプミスですか? 1つがあります。 – Michael
それを指摘してくれてありがとう、ここでバックスラッシュをエスケープする必要があるようです。しかし、はい間違っている、別のバックスラッシュを意味していた。 –