来源:http://blog.csdn.net/qq459805661/article/details/50825513
今天在用JAVA读取XML数据时出现的在这个异常,java.net.MalformedURLException: no protocol
初次判断是编码问题,然后上网搜了一下找到解决的办法。
我的代码是
- DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
- DocumentBuilder builder=factory.newDocumentBuilder();
- Document doc = builder.parse(send);
在这里我只需要设置一下编码就可以了,如下结果
- DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
- DocumentBuilder builder=factory.newDocumentBuilder();
- 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没有设置字符集,所以读取的时候就异常