Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.beans.XMLEncoder;

import java.io.BufferedOutputStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStream;
import java.io.Serializable;

public class Main {
    public static void serializeObjectToFile(final String filePath, final Serializable objectToSeralize)
            throws FileNotFoundException, IOException {

        try (OutputStream file = new FileOutputStream(filePath);
                OutputStream buffer = new BufferedOutputStream(file);
                XMLEncoder output = new XMLEncoder(buffer);) {
            output.writeObject(objectToSeralize);
        }
    }
}