集册 Java实例教程 将Java bean转换为Xml

将Java bean转换为Xml

欢马劈雪     最近更新时间:2020-01-02 10:19:05

558
将Java bean转换为Xml
/* 来 自 时 代 J a v a 公 众 号*/


//package com.nowjava;


import java.beans.XMLEncoder;

import java.io.*;


public class Main {

    public static void main(String[] argv) throws Exception {

        Object bean = "nowjava.com";

        System.out.println(beanToXml(bean));

    }


    public static String beanToXml(Object bean) {


        ByteArrayOutputStream os = new ByteArrayOutputStream(16384);

        try (XMLEncoder e = new XMLEncoder(os)) {
        /**
         from
展开阅读全文