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

我在 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.


UYOU
浏览 73回答 1
1回答

BIG阳

看起来您想要应用从波兰语字母到 ascii 的自定义映射,这超出了stripAccents. 也许您必须自己定义它,例如如下所示(仅显示“Ł”和“ł”)。剧透:不,你不必这样做。Windows 编码上的 ansi 是罪魁祸首。通过正确的解码StringUtils.stripAccents工作得很好。看评论。但如果您离开 stripAccents 的域名...public void Ll() {&nbsp; &nbsp; Map<String, String> map = new HashMap<>();&nbsp; &nbsp; map.put("Ł", "L");&nbsp; &nbsp; map.put("ł", "l");&nbsp; &nbsp; System.out.println(Arrays.stream("ŁałaŁała".split("(?!^)"))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .map(c -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String letter = map.get(c);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return letter == null ? c : letter;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .collect(Collectors.joining("")));}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java