Scala檔案的讀寫操作

541732025發表於2015-11-28

點選(此處)摺疊或開啟

  1. def main(args: Array[String]) {
  2.         val file = Source.fromFile("D:\\test.txt")
  3.         for (line <- file.getLines){ println(line)}
  4.         file.close
  5.         
  6.         val webFile = Source.fromURL("")
  7.         webFile.foreach(print)
  8.         webFile.close
  9.         
  10.         val writer = new PrintWriter(new File("scalaFile.txt" )) //
  11.         for (i <- 1 to 100) writer.println(i)
  12.         writer.close()
  13.         
  14.         print("Please enter your input : " )
  15.         val line = readLine
  16.         println("Thanks, you just typed: " + line)
  17.     }

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28912557/viewspace-1848784/,如需轉載,請註明出處,否則將追究法律責任。

相關文章