Java ObjectOutputStream Write save(Serializable serialized, String filepath)

Here you can find the source of save(Serializable serialized, String filepath)

Description

save

License

Open Source License

Declaration

public static void save(Serializable serialized, String filepath) 

Method Source Code


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

import java.io.File;

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

import java.io.ObjectOutputStream;

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

import java.util.zip.GZIPOutputStream;

public class Main {
    public static void save(Serializable serialized, String filepath) {
        save(serialized, new File(filepath));
    }//from   w  ww  . jav a 2  s .c o m

    public static void save(Serializable serialized, File file) {
        try {
            OutputStream fout = new FileOutputStream(file);
            if (file.getName().endsWith(".gz"))
                fout = new GZIPOutputStream(fout);
            ObjectOutputStream out = new ObjectOutputStream(fout);
            out.writeObject(serialized);
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. loadSerializedObjectWithExceptions(String fileName)
  2. loadTrace(File file)
  3. save(File f, T o)
  4. save(Object o)
  5. save(Object obj, String path)
  6. save(String name, Serializable object)
  7. saveAllPlaying(Object obj, String path)
  8. saveBinary(File dumpFile, Object object)
  9. saveCompressed(String filename, Object o)