创建根节点
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;