java - 德语大写字母的字符集

标签 java string file character-encoding

我尝试写入文件德语符号,但遇到大写字母(例如 Ö)的问题。

小写的符号写得很好。我的 OutputStreamWriter 使用 ISO_8859_1 字符集。

OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.ISO_8859_1);

当我写入文件符号“Ü”时,我希望看到“Ü”,但我看到“/xC3?

最佳答案

我尝试了以下示例,它工作正常:

package com.test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

public class Test {

    public static void main(String[] args) throws IOException {
        //OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.ISO_8859_1);

        OutputStream outputStream = new FileOutputStream("c:\\output.txt");
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream,
                                                                       StandardCharsets.ISO_8859_1);

        outputStreamWriter.write("When it is not possible to use the umlauts (for example, when using a restricted character set) the characters Ä, Ö, Ü, ä, ö, ü should be transcribed as Ae, Oe, Ue, ae, oe, ue respectively, following the earlier postvocalic-e convention; simply using the base vowel (e.g. u instead of ü) would be wrong and misleading. However, such transcription should be avoided if possible, especially with names. Names often exist in different variants, such as \"Müller\" and \"Mueller\", and with such transcriptions in use one could not work out the correct spelling of the name.");

        outputStreamWriter.close();

    }

}

输出:当无法使用变音符号时(例如,使用受限字符集时),字符 Ä、Ö、Ü、ä、ö、ü 应转录为 Ae 、Oe、Ue、ae、oe、ue 分别遵循早期的后元音-e 约定;简单地使用基元音(例如 u 而不是 ü)将是错误且具有误导性的。然而,如果可能的话,应该避免这种转录,尤其是名字。名称通常存在不同的变体,例如“Müller”和“Mueller”,并且使用这种转录方式无法计算出名称的正确拼写。

请告诉我单词是否已正确编码,因为我无法阅读德语。

关于java - 德语大写字母的字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56866966/

相关文章:

java - jstack 结果为 "Windbg Error: WaitForEvent failed"

java - 是否可以将 jasper 报告嵌入到 Python 应用程序中?

python - 如何在Python中将2列表中的单词与另一个单词字符串进行匹配而无需子字符串匹配?

c# - 在 C# 中比较字符串和字符

java - 检查数据库是否存在

java - 使用 Java 生成具有多种功能的报告

java - 如何获取jsf组件的内部内容?

Java:valueOf 与 copyValueOf

c++ - 来自 cpp 文件的部分行最终出现在输出文件中 - 闹鬼代码?

c++ - 将单词和数字的文件输入数组 C++