2017-05-12 7 views
0

Array[String, Int]のデータをファイルに保存しようとしています。しかし、たびに、それが報告されます。Array [String、Int]データをファイルに保存する方法

対象ではない、私はまた、文字列に2つの列を組み合わせて、行ごとにそれを書きたいしようとしたが、それはまだ、このようなエラーを報告

、シリアライズ。コードは次のとおりです。

val fw = new PrintWriter(new File("/path/data_stream.txt")) 

myArray.foreach(x => fw.write((x._1.toString + " " + x._2.toString + "\n").toByte 

答えて

3
import java.nio.file._ 

val data = Array(("one", 1), ("two", 2), ("three", 3)) 
data.foreach(d => Files.write(Paths.get("/path/data_stream.txt"), (d._1 + " " + d._2 + "\n").getBytes, StandardOpenOption.CREATE, StandardOpenOption.APPEND)) 
関連する問題