异常:org.dom4j.DocumentException: 2字节的UTF-8序列的2无效
来源:互联网 发布:热分析软件哪个好 编辑:程序博客网 时间:2024/05/22 17:12
package youling.studio;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by lenovo on 2014/10/20.
*/
public class SougouNews {
public static void main(String[] args) throws Exception {
SougouNews s = new SougouNews();
Document doc = s.parse("C:\\Users\\lenovo\\Desktop\\news_sohusite_xml.smarty.xml");
List<Element> eleDoc = s.getAllElementsByTag(doc,"doc");
for (Element ele:eleDoc){
ele.elementIterator("contenttitle");
Element title = ele.element("contenttitle");
System.out.println(title.getText());
}
}
/**
* 得到指定标签下的指定标签名的所有标签
* @param document
* @param tag
*/
public List<Element> getAllElementsByTag(Document document,String tag){
Element root = document.getRootElement();
List<Element> list = new ArrayList<Element>();
for(Iterator<Element> i = root.elementIterator(tag);i.hasNext();){
Element ele = i.next();
list.add(ele);
}
return list;
}
public Document parse(String filename) throws Exception {
SAXReader reader = new SAXReader();
Document document = reader.read(new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)),"UTF-8")));
return document;
}
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by lenovo on 2014/10/20.
*/
public class SougouNews {
public static void main(String[] args) throws Exception {
SougouNews s = new SougouNews();
Document doc = s.parse("C:\\Users\\lenovo\\Desktop\\news_sohusite_xml.smarty.xml");
List<Element> eleDoc = s.getAllElementsByTag(doc,"doc");
for (Element ele:eleDoc){
ele.elementIterator("contenttitle");
Element title = ele.element("contenttitle");
System.out.println(title.getText());
}
}
/**
* 得到指定标签下的指定标签名的所有标签
* @param document
* @param tag
*/
public List<Element> getAllElementsByTag(Document document,String tag){
Element root = document.getRootElement();
List<Element> list = new ArrayList<Element>();
for(Iterator<Element> i = root.elementIterator(tag);i.hasNext();){
Element ele = i.next();
list.add(ele);
}
return list;
}
public Document parse(String filename) throws Exception {
SAXReader reader = new SAXReader();
Document document = reader.read(new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)),"UTF-8")));
return document;
}
}
此句话是关键:
Document document = reader.read(new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)),"UTF-8")));
就是一个文件编码问题
0 0
- 异常:org.dom4j.DocumentException: 2字节的UTF-8序列的2无效
- org.dom4j.DocumentException: 2 字节的 UTF-8 序列的字节 2 无效。 Nested exception: 2 字节的 UTF-8 序列的字节 2 无效。异常解决办法
- 关于Caused by: org.dom4j.DocumentException: 3 字节的 UTF-8 序列的字节 3 无效。
- Java异常: "2 字节的 UTF-8 序列的字节 2 无效。"的解决方案
- 异常: 2 字节的 UTF-8 序列的字节 2 无效。
- tomcat启动项目异常: 2 字节的 UTF-8 序列的字节 2 无效。
- Java异常 2字节的UTF-8序列的字节2无效
- 2 字节的 UTF-8 序列的字节 2 无效
- 2 字节的 UTF-8 序列的字节 2 无效
- com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效。
- UTF-8 序列的字节 2 无效 utf-8和汉字的转换(真麻烦)
- Tomcat——2 字节的 UTF-8 序列的字节 2 无效
- Tomcat——2 字节的 UTF-8 序列的字节 2 无效
- spring MalformedByteSequenceException:2字节的 UTF-8 序列的字节 2无效
- ant打包 报错 3 字节的 UTF-8 序列的字节 2 无效
- eclipse 3字节的UTF-8序列的字节2无效
- MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 2 无效
- MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 2 无效
- 果冻新闻的项目,虽然很难,但是,还是坚持下来
- 广度/宽度优先搜索(BFS)
- 获取sqlserver连接项的简便方法及QTP连接数据库
- Swift跨region数据迁移问题
- 还有一个聊天客户端的项目,让我深深的认识了自己
- 异常:org.dom4j.DocumentException: 2字节的UTF-8序列的2无效
- ios 实现抽屉功能
- Sicily 1155. Can I Post the lette
- 基于AsyncHttpClient源码改造同步的LHttpClient
- BZOJ 3673 可持久化并查集 by zky 可持久化并查集
- android中的color使用总结
- 如何让百度网盘的分享死链复活?
- GitHub for windows出现remote origin already exists问题
- Android动态设置VIew宽高