当前位置: 技术问答>java相关
奇怪的问题,请高手出击!!
来源: 互联网 发布时间:2015-10-17
本文导语: 我用下面的程序,取出一个xml文件,然后保存这个文件。当用一个正确的xml文件作参数时,可以正确运行,但把生成的文件再次作为参数时,出现下面的错误,并且生成的xml文件不能用IE正确打开。请问怎样解决?源...
我用下面的程序,取出一个xml文件,然后保存这个文件。当用一个正确的xml文件作参数时,可以正确运行,但把生成的文件再次作为参数时,出现下面的错误,并且生成的xml文件不能用IE正确打开。请问怎样解决?源程序是完整的application,方便大家试验。
错误:
Exception in thread "main" org.xml.sax.SAXParseException: org.apache.crimson.par
ser/P-076 Unconvertible UTF-8 character beginning with 0xb8
at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1038)
at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1010)
at org.apache.crimson.parser.InputEntity.peek(InputEntity.java:841)
at org.apache.crimson.parser.Parser2.peek(Parser2.java:2927)
at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:999)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:485)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:304)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl
.java:179)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:134)
at aa.main(aa.java:17)
源程序:import javax.swing.UIManager;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class aa {
public static void main(String[] args) throws Exception{
String xmlfilename=args[0];
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlfilename);
DataOutputStream outxml;
try{
outxml=new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(
xmlfilename)));
//outxml.writeChars(new String(doc.getDocumentElement().toString()));
//outxml.flush();
PrintStream ps=new PrintStream((OutputStream)outxml);
ps.println(doc.getDocumentElement());
ps.flush();
}catch(FileNotFoundException e){System.out.println("file not found!");}
catch(IOException e){System.out.println("there is a ioexception");}
}
}
错误:
Exception in thread "main" org.xml.sax.SAXParseException: org.apache.crimson.par
ser/P-076 Unconvertible UTF-8 character beginning with 0xb8
at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1038)
at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1010)
at org.apache.crimson.parser.InputEntity.peek(InputEntity.java:841)
at org.apache.crimson.parser.Parser2.peek(Parser2.java:2927)
at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:999)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:485)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:304)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl
.java:179)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:134)
at aa.main(aa.java:17)
源程序:import javax.swing.UIManager;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class aa {
public static void main(String[] args) throws Exception{
String xmlfilename=args[0];
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlfilename);
DataOutputStream outxml;
try{
outxml=new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(
xmlfilename)));
//outxml.writeChars(new String(doc.getDocumentElement().toString()));
//outxml.flush();
PrintStream ps=new PrintStream((OutputStream)outxml);
ps.println(doc.getDocumentElement());
ps.flush();
}catch(FileNotFoundException e){System.out.println("file not found!");}
catch(IOException e){System.out.println("there is a ioexception");}
}
}
|