Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.BufferedInputStream;

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

import java.io.IOException;

public class Main {
    public static Object readBeanFromXml(String path) throws Exception {
        FileInputStream fis = null;
        Object aplicacion = null;
        BufferedInputStream bis = null;
        try {
            fis = new FileInputStream(path);
            bis = new BufferedInputStream(fis);
            XMLDecoder xmlDecoder = new XMLDecoder(bis);
            aplicacion = (Object) xmlDecoder.readObject();

        } catch (FileNotFoundException ex) {
            throw new Exception("File to read not found.", ex);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException ex) {
                    throw new Exception("File to close FileInputStream after read.", ex);
                }
            }

            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException ex) {
                    throw new Exception("File to close BufferedInputStream after read.", ex);
                }
            }
        }

        return aplicacion;

    }
}