Here you can find the source of saveMap(String filename, Map
Parameter | Description |
---|---|
filename | The name of the file to which to save. |
map | The String-to-String map to save. |
Parameter | Description |
---|---|
IOException | an exception |
public static void saveMap(String filename, Map<String, String> map) throws IOException
//package com.java2s; //License from project: Open Source License import java.util.*; import java.io.*; public class Main { /**//from ww w .j a va 2 s.co m * Saves a map to a file with the given name -- by default, calls the corresponding * saveMap() function with a "reverse" parameter of <i>false</i>. * * @param filename The name of the file to which to save. * @param map The String-to-String map to save. * @throws IOException */ public static void saveMap(String filename, Map<String, String> map) throws IOException { saveMap(filename, map, false); } /** * Saves a map to a file with the given name. * * @param filename The name of the file to which to save. * @param map The String-to-String map to save. * @param reverse If true, saves a map not of key:value, but of value:key. * @throws IOException */ public static void saveMap(String filename, Map<String, String> map, boolean reverse) throws IOException { BufferedWriter w = new BufferedWriter(new FileWriter(filename)); for (String k : map.keySet()) { String v = map.get(k); if (reverse) { w.write(v + "\t" + k + "\n"); } else { w.write(k + "\t" + v + "\n"); } } w.close(); } }