需要dom4j的jar包
Document doc = saxReader.read(new ByteArrayInputStream(fileString.getBytes())); // Element rootElement = doc.getRootElement(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8"); XMLWriter writer = new XMLWriter(new FileWriter(outFile),format); writer.write(doc); writer.close();原文链接:https://www.f2er.com/xml/299561.html