当前位置: 技术问答>java相关
请问怎样可以将用jdom从xml文件中读取出来的数据转换为中文(gb2312)
来源: 互联网 发布时间:2015-10-04
本文导语: xml也是定义为gb2312的 在线等待,解决立即给分! | TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"gb2312"); ...
xml也是定义为gb2312的
在线等待,解决立即给分!
在线等待,解决立即给分!
|
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING,"gb2312");
StreamResult result = new StreamResult("d:/test.xml");
transformer.transform(new DOMSource(dom),result);
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING,"gb2312");
StreamResult result = new StreamResult("d:/test.xml");
transformer.transform(new DOMSource(dom),result);
|
在XML中定义为gb2312就应该没问题了
要不试试
SAXBuilder的
Document build(java.io.Reader characterStream)
This builds a document from the supplied Reader.
/////////////////
FileInputStream fis = new FileInputStream("yourFile.xml");
InputStreamReader isr = new InputStreamReader(fis,"gb2312");
yourSAXBuilder.build(isr);
要不试试
SAXBuilder的
Document build(java.io.Reader characterStream)
This builds a document from the supplied Reader.
/////////////////
FileInputStream fis = new FileInputStream("yourFile.xml");
InputStreamReader isr = new InputStreamReader(fis,"gb2312");
yourSAXBuilder.build(isr);
|
文档里有一篇这样的文章,里面就有中文的,我试了,读出来没有问题的
在文档里查找一下:)]
在文档里查找一下:)]