利用dom解析xml文件时发现,如果xml文件不小心写错了格式,java会报SAXPaeseException,但是,回头将格式更正后,仍旧报这个错误,而事实上这个错误已经更正。如果将程序重启一次再次解析则解析正确。不知道这里头是什么原因,请教各位大牛。
public void readXMLDocument(String path){
if(XMLCHeck.path.equals(path)&&dom!=null{
return;
}
XMLCheck.path=path;
File file=new File(path);
try{
dom=builder.parse(file);
}catch(IOException e){
e.printStackTrace();
}catch(SAXException e){
e.printStackTrace();
JOptionPane.showMessageDialog(ExpImportUI.getInstance(),"XML解析错误,请检查XML文件,然后重试一遍("+e.getMessage()+")","XML解析错误",JOptionPane.ERROR_MESSAGE);
}catch(IllegalArgumentException e){
e.printStackTrace();
}}
public void readXMLDocument(String path){
if(XMLCHeck.path.equals(path)&&dom!=null{
return;
}
XMLCheck.path=path;
File file=new File(path);
try{
dom=builder.parse(file);
}catch(IOException e){
e.printStackTrace();
}catch(SAXException e){
e.printStackTrace();
JOptionPane.showMessageDialog(ExpImportUI.getInstance(),"XML解析错误,请检查XML文件,然后重试一遍("+e.getMessage()+")","XML解析错误",JOptionPane.ERROR_MESSAGE);
}catch(IllegalArgumentException e){
e.printStackTrace();
}}
楼主说的这么神秘,呵呵,看看有什么流没close么?