java XML文件的保存,不要忘记关闭流。 //保存xml文件 TransformerFactory transformerFactory=TransformerFactory.newInstance(); Transformer transformer=transformerFactory.newTransformer(); DOMSource domSource=new DOMSource(document); //设置编码类型 transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); StreamResult result=new StreamResult(new FileOutputStream(dir+"lang_new.xml")); //把DOM树转换为xml文件 transformer.transform(domSource, result); result.getOutputStream().close();