简体   繁体   English

SWT浏览器不接受编码为cp1251的参数字符串

[英]SWT browser does not accept the argument string encoded cp1251

I have a xml file encoded cp1251 and I want to view it in swt browser, but browser.getText() return null if I run this code. 我有一个编码为cp1251的xml文件,我想在swt浏览器中查看它,但是如果运行此代码,browser.getText()返回null。

//....
String fileEncoding = "UTF-8"
byte[] encoded = Files.readAllBytes(Paths.get(file.toURI()));
String text = new String(encoded,fileEncoding);
browser.setText(text); 

I had read that browser set string encoded Unicode, mb I wrong encoded string from cp1251 to utf-8, or has another way to see my file in browser 我已经看过浏览器设置了字符串编码的Unicode,mb从cp1251到utf-8的编码字符串错误,或者有另一种方式在浏览器中查看我的文件

Maybe you should change the UTF-8 encoding to cp1251 ? 也许您应该将UTF-8编码更改为cp1251?

Because java internally use own encoding UTF-16, you need to tell in which encoding you read your file, and you read it as UTF-8, but i think you need to read it as cp1251, bacause you said that your xml is encoded in cp1251, so you should read it like this: 因为Java内部使用自己的编码UTF-16,所以您需要告诉您以哪种编码读取文件,并且将其读取为UTF-8,但是我认为您需要将其读取为cp1251,因为您说过您的xml已编码在cp1251中,因此您应该这样阅读:

String fileEncoding = "cp1251"
byte[] encoded = Files.readAllBytes(Paths.get(file.toURI()));
String text = new String(encoded,fileEncoding);
browser.setText(text); 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM