java读取xml时候编码格式报no protocol异常

来源:http://blog.csdn.net/qq459805661/article/details/50825513

今天在用JAVA读取XML数据时出现的在这个异常,java.net.MalformedURLException: no protocol

初次判断是编码问题,然后上网搜了一下找到解决的办法。

我的代码是

[java]  view plain  copy
  1. DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();   
  2.                     DocumentBuilder builder=factory.newDocumentBuilder();   
  3.                     Document doc = builder.parse(send);  


在这里我只需要设置一下编码就可以了,如下结果

[java]  view plain  copy
  1. DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();   
  2. DocumentBuilder builder=factory.newDocumentBuilder();   
  3. Document doc = builder.parse(new InputSource(new ByteArrayInputStream(send.getBytes("utf-8"))));  

System.out.print("接口调用状态:" + doc.getElementsByTagName(retno).item(0).getFirstChild().getNodeValue());

rretno为读取的XML中的元素

,现在总结一下,出现以上这个问题的原因是,读取的XML没有设置字符集,所以读取的时候就异常

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值