Java Utililty Methods ObjectOutputStream Write

List of utility methods to do ObjectOutputStream Write

Description

The list of methods to do ObjectOutputStream Write are organized into topic(s).

Method

voidsaveSerializableObject(Object obj, String path)
save Serializable Object
FileOutputStream fout = new FileOutputStream(path);
BufferedOutputStream bout = new BufferedOutputStream(fout);
ObjectOutputStream oos = new ObjectOutputStream(bout);
try {
    oos.writeObject(obj);
} finally {
    oos.flush();
    oos.close();
...
voidsaveSerialized(Serializable obj, File file)
save Serialized
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
out.writeObject(obj);
out.close();
voidsaveStringToFile(String filepath, String content)
save String To File
ByteArrayInputStream is = new ByteArrayInputStream(content.getBytes());
java.io.FileOutputStream fos = new java.io.FileOutputStream(new File(filepath));
while (is.available() > 0) {
    fos.write(is.read());
fos.close();
is.close();
voidsaveToFile(File f, Object obj)
save To File
try (FileOutputStream fis = new FileOutputStream(f, false)) {
    fis.write(compress(objectToByte(obj)));
    fis.flush();
    fis.close();
voidsaveToFile(final File file, final Object obj)
save To File
final FileOutputStream fileOS = new FileOutputStream(file);
try (DataOutputStream dataOS = new DataOutputStream(fileOS)) {
    dataOS.write(serialize(obj));
    dataOS.flush();
voidsaveToFile(Serializable object, File file, boolean compress)
save To File
try {
    OutputStream ostream = new FileOutputStream(file);
    if (compress) {
        ostream = new GZIPOutputStream(ostream);
    ObjectOutputStream stream = new ObjectOutputStream(ostream);
    stream.writeObject(object);
    stream.close();
...
voidsaveToFile(String string, File file, boolean append)
save To File
FileWriter fw = null;
try {
    fw = new FileWriter(file, append);
    PrintWriter out = new PrintWriter(fw);
    out.print(string);
    out.close();
} catch (IOException ex) {
    throw ex;
...