解码UTF-8字符串,然后在8859-2中将其编码为斯洛伐克字母 [英] Decoding UTF-8 String, then encoding it in 8859-2 for Slovakian alphabet

查看:99
本文介绍了解码UTF-8字符串,然后在8859-2中将其编码为斯洛伐克字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字符串翻译成斯洛伐克字母(8859-2编码) 通过我创建的匹配表. 问题是某些字符实际上并未更改,并且输出字符串显示了?"对于某些斯洛伐克字符.

I'm trying to translate strings into Slovakian alphabet (8859-2 encoding) via a matching table I created. Problem is some characters do not actually change and the output string shows me "?" for some slovakian character.

我该怎么做? 我首先做了这样的事情:

How do I do that? I did something like this first :

        File tempFile = File.createTempFile("buffer", ".tmp");
        FileWriter fw = new FileWriter(tempFile);
        Reader fr = new FileReader(fileOriginal);
        BufferedReader br = new BufferedReader(fr);

        while (br.ready()) {
            fw.write(br.readLine().replace("#/e#" , "ě").replace("#>E#" , "É")
        }

但是某些字符没有正确替换.

but some Characters are not correctly replaced.

例如,在此字符串中:"allo#> e#de#> E#"(仅作为示例), 它应该给我"alloědeÉ",但是却给我"allo?de?"因为UTF-8无法识别这些字符. 我的Java程序需要做什么才能识别它?

For example, in this String : "allo #>e# de #>E#" (just an example), it should give me "allo ě de É" but it gives me "allo ? de ?" because UTF-8 doesn't recognize these characters. What do I need to do for my java program to recognize it ?

谢谢.

推荐答案

类似的方法对您有用吗?

Does something like this should works for you?

BufferedReader br = new BufferedReader(new InputStreamReader(fr,"UTF-8"));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fw,"8859-2"));
while (br.ready()) {
    bw.write(br.readLine());
}

此代码读取以UTF-8编码的文件内容,并通过以8859-2编码进行写入.

This code reads a file content encoded in UTF-8 and writes by encoding in 8859-2.

这篇关于解码UTF-8字符串,然后在8859-2中将其编码为斯洛伐克字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆