今日遇此问题,本机上正常,项目打成war部署到linux上报此错!
out.startDocument();
out.writeOpen(rootElement);
for(int i=0;i<=10000000;i++){
out.write(testElement);
}
out.writeClose(rootElement);
}catch(SAXException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
finally{
if( out!=null ){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
错误原因:1、jdk版本引用错误了,可能环境变量里引用了错误的jdk
2、可能linux的编码错误了(我的linux里设置了编码为gbk,所以报此错误)
做项目的时候用的框架spring3.0+struts2.0+mybatis
写了一个配置文件 结果报错如下:
XML document structures must start and end within the same entity.
经过仔细检查 除了标签要写对应之外,就是那个中文注释问题, 一定要前后空格 隔开
<!-- 说明 -->
例如:
<!-- 字典表 -->
<select id="getArea" parameterType="java.util.HashMap" resultType="com.genertech.ssp.model.Dictionary">
select f_id as id, f_value as value from t_sys_dictionary where f_code='FPQY'
</select>
中文的注释 例如字典表前后一定要有空格 否则就会报该错误
写了一个配置文件 结果报错如下:
XML document structures must start and end within the same entity.
经过仔细检查 除了标签要写对应之外,就是那个中文注释问题, 一定要前后空格 隔开
<!-- 说明 -->
例如:
<!-- 字典表 -->
<select id="getArea" parameterType="java.util.HashMap" resultType="com.genertech.ssp.model.Dictionary">
select f_id as id, f_value as value from t_sys_dictionary where f_code='FPQY'
</select>
中文的注释 例如字典表前后一定要有空格 否则就会报该错误
--------------------------------------------------------分割线-----------------------------------------------------
linux系统上用什么命令查看本机运行的jdk的版本的
JDK有以下几种方法:
1、查找目前所使用的linux下所使用的jdk安装后的目录:echo $JAVA_HOME;
2、获得目前所使用的linux下所使用的jdk的版本java -version;
3、获得所安装后的jdk的版本,在bin目录下输入 ./java -version即可;
在配置好Java环境的情况下可以使用 java -version查看
--------------------------------------------------------------------------------------------------------1、查找目前所使用的linux下所使用的jdk安装后的目录:echo $JAVA_HOME;
2、获得目前所使用的linux下所使用的jdk的版本java -version;
3、获得所安装后的jdk的版本,在bin目录下输入 ./java -version即可;
在配置好Java环境的情况下可以使用 java -version查看
最终解决办法
public void writeToFile(String filePath,String fileName){
Document doc = DocumentHelper.createDocument();
Element rootElement=doc.addElement("root");
rootElement.addAttribute("name", "root");
Element testElement = DocumentHelper.createElement("eleTest");
testElement.addAttribute("name", "testEle");
testElement.addText("this is another text");
testElement.setParent(rootElement);
//XMLWriter out = null;
Document doc = DocumentHelper.createDocument();
Element rootElement=doc.addElement("root");
rootElement.addAttribute("name", "root");
Element testElement = DocumentHelper.createElement("eleTest");
testElement.addAttribute("name", "testEle");
testElement.addText("this is another text");
testElement.setParent(rootElement);
//XMLWriter out = null;
FileOutputStream out = null;
try{
// out = new XMLWriter(new FileWriter(new File(filePath+File.separator+fileName)));更改为
try{
// out = new XMLWriter(new FileWriter(new File(filePath+File.separator+fileName)));更改为
out = new XMLWriter(new FileOutputStream(new File((filePath+File.separator+fileName))))
out.startDocument();
out.writeOpen(rootElement);
for(int i=0;i<=10000000;i++){
out.write(testElement);
}
out.writeClose(rootElement);
}catch(SAXException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
finally{
if( out!=null ){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}