java xml 中文乱码_关于java解析xml中出现中文乱码的问题

最近遇到一个java解析xml中出现中文乱码的问题,由于是第一接触这些东西,所以不是很懂,哪位大仙可以帮帮我@@

java代码:

public class Transform {

private static Transform transform;

public static synchronized Transform getTransform() {

if (transform == null)// 如果还没有创建则创建一个实例

transform = new Transform();

return transform;

}

public void transform(String xml, String xls, String xmlOut)

throws FileNotFoundException, TransformerException {

File xmlFile = new File(xml);

File xsltFile = new File(xls);

File xmlOutFile = new File(xmlOut);

if (xmlFile.exists() && xsltFile.exists()) {// 检查文件是否存在

Source xmlSource = new StreamSource(xmlFile);

Source xsltSource = new StreamSource(xsltFile);

TransformerFactory transFact = TransformerFactory.newInstance();

Transformer trans = null;

trans = transFact.newTransformer(xsltSource);

trans.transform(xmlSource, new StreamResult(System.out));

trans.transform(xmlSource, new StreamResult(new FileOutputStream(

xmlOutFile)));

} else {

throw new FileNotFoundException("文件不存在,请检查文件路径!");

}

}

/*

* 测试函数

*/

public static void main(String[] args) throws Exception {

Transform tran = Transform.getTransform();

tran.transform(".//test.xml",

".//test.xsl",

"xmlOut.xml");

}

}

xml:

Empire Burlesque

Bob Dylan

USA

Columbia

10.90

1985

xslt:

我的CD集

就是里面的“我的cd集”转换后出现了乱码!

谢谢各位了!

问题补充:

我想问一下

具体是怎么样子 的呢??

谢谢

我搞了半天没搞定

2009年5月27日 17:27

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值