003、scala写入读取本地文件操作

    技术2022-07-11  95

    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 }
    Processed: 0.009, SQL: 9