可以使用以下步骤:
import java.io.PrintWriter
import scala.collection.mutable.Map
val dictionary = Map("apple" -> "苹果", "banana" -> "香蕉", "orange" -> "橙子")
val filePath = "dictionary.txt"
val writer = new PrintWriter(filePath)
dictionary.foreach { case (key, value) =>
writer.println(s"$key:$value")
}
writer.close()
完成以上步骤后,字典的内容将以键值对的形式保存到名为dictionary.txt的.txt文件中。
领取专属 10元无门槛券
手把手带您无忧上云