写字节流转换String 代码示例
Posted 陈旭猴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了写字节流转换String 代码示例相关的知识,希望对你有一定的参考价值。
1 public void pushEmployee(EmpPushToTianFangRequest request){ 2 try { 3 StringWriter sw = new StringWriter(); 4 JAXBContext context = JAXBContext.newInstance(EmpPushToTianFangRequest.class); 5 Marshaller marshaller = context.createMarshaller(); 6 marshaller.marshal(request, sw); 7 System.out.println(sw.toString()); 8 } catch (JAXBException e) { 9 e.printStackTrace(); 10 } 11 }
1
marshal方法在JDK中的声明:
void javax.xml.bind.Marshaller.marshal(Object jaxbElement, Writer writer) throws JAXBException
使用
StringWriter 接受
Writer
以上是关于写字节流转换String 代码示例的主要内容,如果未能解决你的问题,请参考以下文章