Java ObjectOutputStream Write saveObjectToPath(T objectToSave, String pathToSaveTo)

Here you can find the source of saveObjectToPath(T objectToSave, String pathToSaveTo)

Description

Attempts to write an object to the provided path, creating the file if it does not already exist.

License

Creative Commons License

Parameter

Parameter Description
objectToSave The object which should be saved
pathToSaveTo The path in which to save the object

Declaration

public static <T extends Object> void saveObjectToPath(T objectToSave, String pathToSaveTo) 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.*;

public class Main {
    /**/*from  w  w  w  .  ja v a  2 s.  co m*/
     * Attempts to write an object to the provided path, creating the file if it does not already
     * exist. Uses the default serialization methods, and as result, it is recommended that in
     * Bukkit applications, it be used in conjunction with the Serialization package
     *
     * @param objectToSave The object which should be saved
     * @param pathToSaveTo The path in which to save the object
     */
    public static <T extends Object> void saveObjectToPath(T objectToSave, String pathToSaveTo) {
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(pathToSaveTo));
            oos.writeObject(objectToSave);
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. saveObjectInFile(String fileName, Object obj)
  2. saveObjectToFile(File file, Object object)
  3. saveObjectToFile(File thatFile, Object... thisObject)
  4. saveObjectToFile(final Object object, final String fileName)
  5. saveObjectToFile(Object obj, String fileName)
  6. saveParameters()
  7. saveResultToStream(ObjectOutputStream oos, Object result)
  8. saveResultToStream(ObjectOutputStream oos, Object result)
  9. saveSerializableObject(Object obj, String path)