[英]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.