import java.io.File
import scala.io.Source
class WorldCount {
var map = Map.empty[String, Int]
def scanDir(file: File) {
file.listFiles().foreach { f => if (f.isFile()) readFile(f) }
}
def readFile(file: File) {
val f = Source.fromFile(file,"utf-8")
for (line <- f.getLines()) {
for (word <- line.split("\t|,|\\\\|\\+|\\-|\\(|\\)|\\[|\\]|!|:|\\.|>|<|\\{|\\}|\\?|\\*| |\\/|\"")) {
if (map.contains(word))
map += (word -> (map(word) + 1))
else
map += (word -> 1)
}
}
}
}
object WorldCount {
def main(args: Array[String]): Unit = {
val wordCount = new WorldCount()
wordCount.scanDir(new File("D:\\scalaDir"))
wordCount.map.foreach{x=>println("world:"+x._1+" count:"+x._2)}
}
}