import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; import java.util.Map; public class WriteMapToFile { public static void main(String[] args) { Map<String, String> map = // 假设已经有一个 Map 对象 try { FileWriter writer = new FileWriter("example.txt"); BufferedWriter bufferedWriter = new BufferedWriter(writer); for (Map.Entry<String, String> entry : map.entrySet()) { bufferedWriter.write(entry.getKey() + " : " + entry.getValue()); bufferedWriter.newLine(); } bufferedWriter.close(); } catch (IOException e) { e.printStackTrace(); } } }
标签:map,java,Map,存入,bufferedWriter,io,import From: https://www.cnblogs.com/herd/p/17529646.html