【发布时间】:2022-01-26 10:54:59
【问题描述】:
我想在调度程序中自动将文件放入 FTP 地址。
我有一个 JSON 对象,所以我可以从中创建一个 XML。
我可以用下面的代码创建一个xmlString。
我想将 xmlString 中的 XML 放入 FTP 地址的文件 abc.xml。我该怎么做?
private static String objToXml(Object object) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(object.getClass());
Marshaller marshallerObj = context.createMarshaller();
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
marshallerObj.marshal(object, sw);
return sw.toString();
}
String xmlString = "";
try {
xmlString = objToXml(anObject);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
【问题讨论】: