def write(fileName: String)(datas: Array[String]): Unit = {
val writer = new PrintWriter(new File(fileName))
println("--------数据写入--------")
for (s <- datas) {
// println(s)
writer.write(s + "\n")
}
writer.close()
}
/**
* 数据读取
*
* @param fileName 文件
* @return
*/
def read(fileName: String) = {
val txt_data = Source.fromFile(fileName)
val nodes = new ArrayBuffer[String]()
val array = txt_data.getLines().filter(x => x.isInstanceOf[String]).toArray
array.foreach(
x => {
nodes.append(x)
}
)
nodes
}
003、scala写入读取本地文件操作
最新推荐文章于 2022-07-25 23:17:34 发布