dom4j解析xml用输出流保存

这篇博客介绍了如何使用dom4j解析XML文件,并通过OutputStream将内容以UTF-8编码保存。首先,从文件中读取XML数据,然后通过BufferedReader逐行读取并写入OutputStream。接着,使用SAXReader进行解析,获取XML文档的根元素和特定子节点。最后,遍历子节点进行进一步处理。
摘要由CSDN通过智能技术生成

 //设置集合接受 设备信息
  File f=new File("recordInfo.xml");
    String readin="";
       InputStreamReader read=new InputStreamReader(in);
      
       BufferedReader bureader =new BufferedReader(read);
      
       ArrayList list =new ArrayList();
       OutputStream out;
  try {
   out = new FileOutputStream(f);
     
       //读取数据和输出数据
          while((readin=bureader.readLine())!=null)
          {
           
           log.info("获取的xml文件:"+readin);
           
           out.write(readin.getBytes("utf-8"));
          }
     
          log.info("文件路径:"+f.getAbsolutePath());
          //解析传过来的xml
          SAXReader sax=new SAXReader();
          sax.setEncoding("utf-8");
          Document doc=sax.read(f);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值