Java FileWriter Write saveMap(Map map, String filePath)

Here you can find the source of saveMap(Map map, String filePath)

Description

save Map

License

Apache License

Declaration

public static <K, V> void saveMap(Map<K, V> map, String filePath) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedWriter;

import java.io.FileWriter;
import java.io.IOException;

import java.io.PrintWriter;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static <K, V> void saveMap(Map<K, V> map, String filePath) {
        PrintWriter pw = null;//from  ww w .  j av  a2  s . co m
        try {
            pw = new PrintWriter(new BufferedWriter(new FileWriter(filePath)), true);
        } catch (IOException e) {
            e.printStackTrace();
            exit(1);
        }
        for (Entry<K, V> entry : map.entrySet()) {
            pw.print(entry.getKey());
            pw.print('\t');
            pw.println(entry.getValue());
        }
        pw.close();
    }

    public static void exit(int status) {
        System.exit(status);
    }
}

Related

  1. saveIntegerNodes2File(Integer[] nodes, String fileName)
  2. saveIntNodes2File(int[] nodes, String fileName)
  3. saveList(String listName, Set list)
  4. saveListStringToFile(String filePath, List listString)
  5. saveListToFile(ArrayList list, String filePath)
  6. saveMap(String filename, Map map)
  7. saveMappingFile(File mappingFile, Map messageMap)
  8. saveMeasures(String appDirPath, String fileName, double[] measures)
  9. saveMetaClassToFile(File baseDir, String clazzDef, String metaPackageName, Class fromClazz)