Java Utililty Methods Object Save

List of utility methods to do Object Save

Description

The list of methods to do Object Save are organized into topic(s).

Method

booleanwriteObject(File f, Object obj)
write Object
boolean retObj = true;
if (!f.getParentFile().isDirectory()) {
    f.getParentFile().mkdirs();
FileOutputStream fileOutputStream = null;
ObjectOutputStream objectOutputStream = null;
try {
    fileOutputStream = new FileOutputStream(f);
...
voidwriteObject(File f, Serializable obj)
Serializes an object to a file, masking out annoying exceptions.
try {
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
    oos.writeObject(obj);
    oos.close();
} catch (IOException e) {
    System.err.println("Exception writing file " + f + ": " + e);
voidwriteObject(File file, Object obj)
Write one object to the specified file.
createFileIfNotExist(file);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(obj);
oos.close();
voidwriteObject(File file, Object object)
writes the spcified object to the file specified
mkdirs(file);
ObjectOutputStream output = null;
try {
    output = new ObjectOutputStream(new FileOutputStream(file));
    output.writeObject(object);
} finally {
    close(output, file);
voidwriteObject(File file, Object object)
write Object
try {
    FileOutputStream fileOut = new FileOutputStream(file);
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(object);
    out.close();
    fileOut.close();
} catch (IOException e) {
    e.printStackTrace();
...
voidwriteObject(File file, Object object)
write Object
mkdirs(file.getParentFile());
OutputStream outputStream = null;
try {
    outputStream = new FileOutputStream(file);
    @SuppressWarnings("resource")
    ObjectOutputStream oos = new ObjectOutputStream(outputStream);
    oos.writeObject(object);
    oos.flush();
...
voidwriteObject(File file, Object object)
write Object
try (ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file))) {
    outputStream.writeObject(object);
    outputStream.flush();
} catch (IOException e) {
    throw new RuntimeException(e);
voidwriteObject(File file, Object object)
write Object
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(object);
oos.flush();
oos.close();
voidwriteObject(File outFile, Object data)
write Object
FileOutputStream fileOut = new FileOutputStream(outFile);
ObjectOutputStream outStream = new ObjectOutputStream(fileOut);
try {
    outStream.writeObject(data);
} finally {
    outStream.close();
    fileOut.close();
voidwriteObject(Object data, String filename)
write Object
File file = new File(filename);
if (!file.exists()) {
    file.getParentFile().mkdirs();
    file.createNewFile();
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(data);
...