简体   繁体   English

正确显示(抛光)字符

[英]Display (polish) characters properly

I'm reading an xml-file which contains german, french, spanish, english and polish text. 我正在读一个包含德语,法语,西班牙语,英语和波兰文的xml文件。

To handle the polish letters (which caused the most trouble) i tried to do it like this: 为了处理抛光字母(这导致最麻烦)我试图这样做:

File file = new File(path);
InputStream is = new FileInputStream(file);
Reader reader = new InputStreamReader(is, charset);

InputSource src = new InputSource(reader);
src.setEncoding(charset.name());

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

saxParser.parse(src, handler);

The problem i encountered was that none of the default charsets display the text properly. 我遇到的问题是没有任何默认的字符集正确显示文本。 Some have questionmarks in it some have a combination of other chars in it eg ÄÖ.. 有些人在其中有一些问号,其中有一些其他字符组合,例如Ä..

To break it a bit down I wrote another snippet to test which charset works: 为了打破它,我写了另一个片段来测试哪个charset工作:

public static void main(String[] args){
        Charset charset = StandardCharsets.UTF_8;
        String chars = "śłuna długie";
        System.out.println(new String(chars.getBytes(charset), charset));
}

Again tested every single one but nothing works.. I hope you've got an idea. 再次测试每一个,但没有任何作用..我希望你有一个想法。

My solution: Change the encoding of your ide 我的解决方案:更改ide的编码

I used the default encoding of my ide (intellij) which was "windows-1252", due to the fact that I'm using windows on this pc. 我使用了我的ide(intellij)的默认编码,它是“windows-1252”,因为我在这台电脑上使用了Windows。

So I changed it to UTF-8 and the short test code worked fine for me. 所以我将它改为UTF-8,简短的测试代码对我来说很好。

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

相关问题 文件Java中的波兰语字符 - Polish characters in file java 如何计算.txt文件中波兰语字符的出现 - How to count occurrence of Polish characters in .txt file 波兰语中“数字”组分隔符的ISO字符是什么? - What is the ISO characters for the Numbers group separator in Polish? 用于波兰语字符的oracle jdbc unicode无法正常工作 - oracle jdbc unicode for polish character is not working properly 尽管终端配置正确,Java也无法显示Unicode字符 - Java can't display Unicode characters despite properly configured terminal Spring Hibernate无法保存带有修饰符的数据(UTF-8问题) - Spring Hibernate unable save data with polish characters (UTF-8 issue) Hibernate函数lower和upper不适用于波兰语特殊字符 - Hibernate functions lower and upper not working on Polish special characters 如何使用Velocity模板正确显示西班牙语字符? - How do I get Spanish characters to display properly using a Velocity template? Java 中的逆波兰表示法。 检查不应该在字符串数组中的任何符号或字符(正则表达式) - Reverse Polish notation in Java. Checking for any symbols or characters (regex), that should not be in a string array 使用iText创建PDF时,从命令行执行时特殊字符正确显示,而从应用程序中不显示 - Using iText to create PDF, special characters display properly when executed from command line don't display from app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM