Java Collection Serialize serializeMap(Map map, File file)

Here you can find the source of serializeMap(Map map, File file)

Description

Serialize a Map.

License

Apache License

Parameter

Parameter Description
map The map to serialize.
file The file for saving the map.

Declaration

public static void serializeMap(Map<?, ?> map, File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2012//  w  w w .  j  av  a 2 s  . c om
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universit?t Darmstadt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/

import java.io.File;

import java.io.FileOutputStream;

import java.io.ObjectOutputStream;
import java.util.Map;

public class Main {
    /**
     * Serialize a Map.
     * 
     * @param map The map to serialize.
     * @param file The file for saving the map.
     */
    public static void serializeMap(Map<?, ?> map, File file) {
        try {
            ObjectOutputStream os = new ObjectOutputStream(
                    new FileOutputStream(file));
            os.writeObject(map);
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. serialize(List features)
  2. serialize(Map> in, OutputStream out)
  3. serializeSet(Set set)
  4. SerializeVectorOfInts(Vector m)