Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.Closeable;

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

import java.io.IOException;

import java.io.ObjectInputStream;

public class Main {
    public static Object getBeanFromFile(String filePath) {
        Object bean = null;
        File file = new File(filePath);
        ObjectInputStream inputStream = null;
        if (!file.exists()) {
            return bean;
        }
        try {
            inputStream = new ObjectInputStream(new FileInputStream(file));
            bean = inputStream.readObject();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            closeQuiltly(inputStream);
        }

        return bean;
    }

    public static void closeQuiltly(Closeable closeable) {
        if (null != closeable) {
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}