Java Object Serialize serialize(String path, String name, Object obj)

Here you can find the source of serialize(String path, String name, Object obj)

Description

serialize

License

Apache License

Declaration

public static void serialize(String path, String name, Object obj) 

Method Source Code


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

import java.io.File;

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

import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
    public static void serialize(String path, String name, Object obj) {
        checkPath(path);/*w  w w. j av a  2s.c  o m*/
        if (!(obj instanceof Serializable)) {
            return;
        }
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream(path + name));
            oos.writeObject(obj);
            oos.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private static void checkPath(String path) {
        File pathFile = new File(path);
        if (!pathFile.exists()) {
            pathFile.mkdirs();
        }
    }
}

Related

  1. serialize(Serializable object, String fileName)
  2. serialize(Serializable s, File dir, String fileName)
  3. serialize(Serializable serializable)
  4. serialize(Serializable... objects)
  5. serialize(String filename, T obj)
  6. serialize(T obj)
  7. serialize(T obj)
  8. serialize(T object)
  9. serialize(T object)