Here you can find the source of saveNamesToFile(Map
public static File saveNamesToFile(Map<String, Integer> namesMap, Path namesFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.file.Path; import java.util.*; public class Main { public static File saveNamesToFile(Map<String, Integer> namesMap, Path namesFile) throws IOException { final File names = namesFile.toFile(); try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(names))) { for (Map.Entry<String, Integer> entry : namesMap.entrySet()) { bufferedWriter.write(String.valueOf(entry.getValue())); bufferedWriter.write("\t"); bufferedWriter.write(entry.getKey()); bufferedWriter.newLine(); }//from w w w .ja v a 2s . c om } return names; } }