我有这个代码:
DocumentBuilderFactory builderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = builderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document document = null;
try {
URL url = new URL("http://en.wikipedia.org/wiki/Charlie_Chaplin");
//Reader reader = new InputStreamReader(url.openStream(),"UTF-8");
document = builder.parse(url.openStream());
} catch (SAXException e) {
e.printStackTrace();
return;
} catch (IOException e) {
e.printStackTrace();
return;
}
在我尝试处理的页面上,出现以下异常:
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:1 字节 UTF-8 序列的字节 1 无效。
如何将页面更改为 UTF-8?或者,我还有什么其他方法可以解决这个问题?