import java.io.PrintWriter
import java.io.File
import scala.io.Source
object FileOps {
def main(args:Array[String]){
//文件读取
val file=Source.fromFile("D:\a.txt")
for(line <- file.getLines)
{
println(line)
}
file.close
文件追加------------------------------<><><>
1.FileWriter
import java.io.FileWriter
val out = new FileWriter("/root/test/test.txt",true)
for (i <- 0 to 15){
out.write(i.toString)
out.close()
}
//文件写入
val writer = new PrintWriter(new File("D:\saveTextTitle.txt"))
for(i <- 1 to 10)
writer.println(i)// 这里是自动换行 不用再加
切记切记
writer.close()
}
}