Java ObjectOutputStream Write saveIndex(String path, Serializable obj)

Here you can find the source of saveIndex(String path, Serializable obj)

Description

save Index

License

Open Source License

Declaration

static public boolean saveIndex(String path, Serializable obj) 

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.Serializable;

public class Main {
    public static String EXTENSION = "drivemandb";
    private static String OS = System.getProperty("os.name").toLowerCase();

    static public boolean saveIndex(String path, Serializable obj) {
        path += "." + EXTENSION;
        boolean res = true;

        File file = new File(path);
        if (file.exists() && file.isFile()) {
            if (file.delete()) {
                System.out.println("deleted ori index");
            }/*from w  w w  . java  2 s  .  c o  m*/
        }

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(path);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(obj);

            oos.close();
            if (OS.indexOf("win") >= 0) {
                Runtime.getRuntime().exec("attrib +H " + path);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            res = false;
        } finally {
            try {
                if (fos != null)
                    fos.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return res;

    }
}

Related

  1. saveData(Object data, String filename)
  2. saveDate(String path, Object obj)
  3. saveFile(Object o, File file)
  4. saveFile(Object o, String filename)
  5. saveGZipObject(Object toSave, File file)
  6. saveInSerFile(String filename, T object)
  7. saveObject(File file, Object o, boolean overwrite)
  8. saveObject(File file, Serializable obj)
  9. saveObject(Object o, File f)