Object Xml Decoder using Java Bean XML Decoder - Java XML

Java examples for XML:XML Java Bean

Description

Object Xml Decoder using Java Bean XML Decoder

Demo Code


//package com.java2s;
import java.beans.XMLDecoder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] argv) throws Exception {
        String objSource = "java2s.com";
        System.out.println(ObjectXmlDecoder(objSource));
    }//from ww w.j  a  v a2 s .  c o  m

    public static List ObjectXmlDecoder(String objSource)
            throws FileNotFoundException, IOException, Exception {
        List objList = new ArrayList();
        File fin = new File(objSource);
        FileInputStream fis = new FileInputStream(fin);
        XMLDecoder decoder = new XMLDecoder(fis);
        Object obj = null;
        try {
            while ((obj = decoder.readObject()) != null) {
                objList.add(obj);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
        }
        fis.close();
        decoder.close();
        return objList;
    }
}

Related Tutorials