我用public static boolean doc2XmlFile(Document document,String filename){ 
      boolean flag = true; 
      try 
      { 
            /** 将document中的内容写入文件中  */ 
            TransformerFactory tFactory = TransformerFactory.newInstance();    
            Transformer transformer = tFactory.newTransformer();  
            /** 编码 */ 
            //transformer.setOutputProperty(OutputKeys.ENCODING, "GB2312"); 
            DOMSource source = new DOMSource(document);  
            StreamResult result = new StreamResult(new File(filename));    
            transformer.transform(source, result);  
        }catch(Exception ex) 
        { 
            flag = false; 
            ex.printStackTrace(); 
        } 
        return flag;      
    } 
方法把修改后的xml写进去,不知道怎么取相对路径。。