java生成报文_生成xml报文方法并输出

创建根节点

Element root= new Element("root");

//创建报文体

Element body = new Element("body");

//添加子节点并赋值

body.addContent(new Element("SEQ_NO").setText(""));

//获取已存在的节点并赋值(只能一层一层的获取)

body.getChild("SEQ_NO").getChild("SEQ_NO2").setText(""));;

//获取已存在的节点的值

String str=Message_Body.getChildText("EP_DEC_HEAD");

//根节点(报文)添加到文档中;

Document Doc = new Document(root);

//自定义报文名字

String FileName = "EMVS_EP_3120980024_"+hm.get("CONTR_NO")+"_"+BIZ_TYPE+"0_"+nowTime+".DEC";

//输出报文到项目WebRoot目录

Format format = Format.getPrettyFormat();

XMLOutputter XMLOut = new XMLOutputter(format);

//XMLOut..setEncoding("utf-8");Doc.setXMLEncoding("gb2312");

//获得WebRoot路径

// ServletConfig servletConfig=(ServletConfig).getServletContext().getAttribute("servletConfig");

String webRootPath=request.getSession().getServletContext().getRealPath("/");

String uploadPath="download\\dadan\\";

//uploadPath附加传入的路径,组成一个上传的完整路径

uploadPath=webRootPath+uploadPath;

XMLOut.output(Doc, new FileOutputStream(uploadPath+fileName));

//利用ftp发送文件到指定文件夹

File file = new File(uploadPath+fileName);

FTPFunc fTPFunc = new FTPFunc();

fTPFunc.connect("send");

fTPFunc.upload(file);

ftp连接,上传,下载工具类

package com.util;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.util.ArrayList;

import org.apache.commons.net.ftp.FTPClient;

import org.apache.commons.net.ftp.FTPFile;

import org.apache.commons.net.ftp.FTPReply;

import seastar.servlet.demand.Utils;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值