请教:用Dom4j处理中文的问题
写了一个简单的程序如下:
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("config");
root.setText("oktest测试");
File file = new File("c:\\config.xml");
try
{
OutputFormat format= OutputFormat.createPrettyPrint();
format.setEncoding("utf-8");
XMLWriter writer = new XMLWriter(new FileWriter(file), format);
writer.write(doc);
writer.close();
System.out.println("write success");
}
catch(Exception e)
{}
虽然输出 write success,但用IE打开时报错,错就在中文字符“测试”。
我将 format.setEncoding("utf-8"); 改成 format.setEncoding("GBK");之后就可以正常在IE中显示。
请问,为什么用UTF-8不能呢?