Java Object Save writeObject(Object data, String filename)

Here you can find the source of writeObject(Object data, String filename)

Description

write Object

License

LGPL

Declaration

private static void writeObject(Object data, String filename) throws IOException 

Method Source Code


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

import java.io.File;

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

import java.io.ObjectOutputStream;

public class Main {
    private static void writeObject(Object data, String filename) throws IOException {

        File file = new File(filename);
        if (!file.exists()) {
            file.getParentFile().mkdirs();
            file.createNewFile();/*  w w w. ja va 2 s. c o m*/
        }
        FileOutputStream fileOut = new FileOutputStream(file);
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        out.writeObject(data);
        out.close();
        fileOut.close();

    }
}

Related

  1. writeObject(File file, Object object)
  2. writeObject(File file, Object object)
  3. writeObject(File file, Object object)
  4. writeObject(File file, Object object)
  5. writeObject(File outFile, Object data)
  6. writeObject(Object i)
  7. writeObject(Object o, File f)
  8. writeObject(Object o, File path)
  9. writeObject(Object o, ObjectOutput dos)