简体   繁体   English

Java-俄语编码

[英]Java - Russian Encoding

I'm trying to print Russian text like the below example but got ? 我正在尝试像下面的示例一样打印俄语文本,但是得到了? characters. 字符。 I have tried multiple "encodings" but the same result. 我尝试了多种“编码”,但结果相同。

public static void main(String[] args) throws Exception {
        String t = "тест";
        System.out.println("test: " + t);
    }

Output: test: ???? 输出:测试:????

How can I do right encoding? 如何正确编码?

The characters that you see couldn't be decoded properly on the device displaying them. 您看到的字符在显示它们的设备上无法正确解码。 It could be many reasons, but the main cause is the device is using another encoding scheme. 可能有很多原因,但主要原因是设备正在使用其他编码方案。 To properly encode character stream use the following code that writes to the file. 要正确编码字符流,请使用以下代码写入文件。

public static void main(String[] args) throws Exception {
    OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream("myFile.txt"), "windows-1251");

    String t = "тест";
    fileWriter.write("test: " + t);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM