Java Object Serialize serialize(Object obj, String file)

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

Description

serialize

License

Open Source License

Declaration

public static void serialize(Object obj, String file) 

Method Source Code


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

import java.io.BufferedOutputStream;

import java.io.File;

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

import java.io.ObjectOutputStream;

public class Main {
    public static void serialize(Object obj, String file) {
        try {/*from   www.  j  a v a2s .com*/
            int lastDash = Math.max(file.lastIndexOf('\\'), file.lastIndexOf('/'));
            if (lastDash != -1)
                new File(file.substring(0, lastDash)).mkdirs();
            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
            out.writeObject(obj);
            out.flush();
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. serialize(Object obj)
  2. serialize(Object obj)
  3. serialize(Object obj)
  4. serialize(Object obj)
  5. serialize(Object obj)
  6. serialize(Object obj, String fileName)
  7. serialize(Object obj, String fileName)
  8. serialize(Object obj, String fname, boolean gzipped)
  9. serialize(Object objData, Class typeOfT)