加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

字符串生成xml文件

发布时间:2020-12-15 23:45:48 所属栏目:百科 来源:网络整理
导读:/** * 字符串,生成xml文件 * @param str * @param fileName * @throws IOException */ public void strChangeXML(String str,String fileName ) throws IOException { SAXReader saxReader = new SAXReader(); Document document; try { document = saxReade
/** * 字符串,生成xml文件 * @param str * @param fileName * @throws IOException */ public void strChangeXML(String str,String fileName ) throws IOException { SAXReader saxReader = new SAXReader(); Document document; try { document = saxReader.read(new ByteArrayInputStream(str.getBytes())); OutputFormat format = OutputFormat.createPrettyPrint(); /** 指定XML字符集编码 */ format.setEncoding("UTF-8"); /** 将document中的内容写入文件中 */ XMLWriter writer = new XMLWriter(new FileWriter(new File(fileName)),format); writer.write(document); writer.close(); } catch (DocumentException e) { // TODOAuto-generatedcatchblock logger.error(e.getMessage()); } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读