java 把map存入文件
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(); } } }
QQ 3087438119