写字节流转换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 代码示例的主要内容,如果未能解决你的问题,请参考以下文章

10个JavaScript代码片段,使你更加容易前端开发。

需要示例代码片段帮助

MapReduce序列化及分区的java代码示例

字节流的示例代码

JavaScript数字和字符串转换示例

为啥在片段中从 char* 转换为 std::string 比转换为 const char* 更可取?