Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.beans.XMLEncoder;
import java.io.*;

public class Main {
    /**
     * Serializes an object into an xml file
     * 
     * @param object object to serialize
     * @param fileName path to file
     */
    public static void encodeToFile(Object object, String fileName) throws FileNotFoundException, IOException {
        XMLEncoder encoder = new XMLEncoder(new FileOutputStream(fileName));
        try {
            encoder.writeObject(object);
            encoder.flush();
        } finally {
            encoder.close();
        }
    }
}