Java ObjectOutputStream Write saveData(HashMap data, String filename)

Here you can find the source of saveData(HashMap data, String filename)

Description

save Data

License

LGPL

Declaration

@SuppressWarnings("rawtypes")
    public static void saveData(HashMap data, String filename) 

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;
import java.util.HashMap;

public class Main {
    @SuppressWarnings("rawtypes")
    public static void saveData(HashMap data, String filename) {
        try {/*from  ww w  .j  a  v  a 2  s .  co m*/
            writeObject(data, filename);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

        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);
        out.close();
        fileOut.close();

    }
}

Related

  1. save(Serializable serialized, String filepath)
  2. save(String name, Serializable object)
  3. saveAllPlaying(Object obj, String path)
  4. saveBinary(File dumpFile, Object object)
  5. saveCompressed(String filename, Object o)
  6. saveData(Object data, String filename)
  7. saveDate(String path, Object obj)
  8. saveFile(Object o, File file)
  9. saveFile(Object o, String filename)