Scala code in one day (9) and scala code in one day
Scala code in one day (9)
To better control spark, I recently studied scala language features, mainly reading "quick learning scala" and writing down some codes that I think are useful.
Package examplesimport scala. io. sourceobject Example9 extends App {val source = Source. fromFile ("/home/linger/data/hive_data", "UTF-8") val lines = source. getLines () for (l <-lines) {println (l)} lines. toArray source. mkString source. close () // you can call some Java io libraries to process files. // The regular expression val wsnumws = "" \ s [0-9] + \ s + """. r // The original string format val wsnumws2 = "\ s [0-9] + \ s + ". r // equivalent to above, but need to be transferred // regular Extraction Machine val numitem = "([0-9] +) ([a-z] + )". r val numitem (num, item) = "99 bottle" println (num, item )}
Author: linger link: http://blog.csdn.net/lingerlanlan/article/details/43970979