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.FileOutputStream;

import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    public static boolean saveBeanToFile(String filePath, Object bean) {
        File file = new File(filePath);
        ObjectOutputStream outputStream = null;
        if (file.exists()) {
            file.delete();
        }

        try {
            outputStream = new ObjectOutputStream(new FileOutputStream(file));
            outputStream.writeObject(bean);

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

        return true;
    }

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