为了账号安全,请及时绑定邮箱和手机立即绑定

读取带有波兰语字母的 ANSI 文件并在控制台中显示(不带重音符号)

读取带有波兰语字母的 ANSI 文件并在控制台中显示(不带重音符号)

UYOU 2023-11-10 16:24:21
我在 file.csv 中有这一行“ĆćĘ꣏źł”,它被编码为 ANSI(如 Notepad++ 显示)。如何在像 CcEeLzzl 这样的控制台中正确显示这一行?为了删除重音,我使用 apache 中的 StringUtils.stripAccents(myLine) 但仍然得到“��Ee����”        FileReader fr = null;        try {            String sCurrentLine;            br = new BufferedReader(new FileReader(fileName2));            while ((sCurrentLine = StringUtils.stripAccents(br.readLine())) != null) {                System.out.println(StringUtils.stripAccents(sCurrentLine));            }        } catch (IOException e) {            e.printStackTrace();        } finally {            try {                if (br != null)                    br.close();                if (fr != null)                    fr.close();            } catch (IOException ex) {                ex.printStackTrace();            }        }```I want in COnsole this "CcEeLzzl", not that "ĆćĘ꣏źł". Please help me.
查看完整描述

1 回答

?
BIG阳

TA贡献1859条经验 获得超6个赞

看起来您想要应用从波兰语字母到 ascii 的自定义映射,这超出了stripAccents. 也许您必须自己定义它,例如如下所示(仅显示“Ł”和“ł”)。


剧透:不,你不必这样做。Windows 编码上的 ansi 是罪魁祸首。通过正确的解码StringUtils.stripAccents工作得很好。看评论。但如果您离开 stripAccents 的域名...


public void Ll() {

    Map<String, String> map = new HashMap<>();

    map.put("Ł", "L");

    map.put("ł", "l");


    System.out.println(Arrays.stream("ŁałaŁała".split("(?!^)"))

            .map(c -> {

                String letter = map.get(c);

                return letter == null ? c : letter;

            })

            .collect(Collectors.joining("")));

}


查看完整回答
反对 回复 2023-11-10
  • 1 回答
  • 0 关注
  • 62 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信