1. Functional programming example WordCount
Task: In accordance with the style of functional programming, write a program to count the word frequency of the words in all files in a certain directory
Method: Please enter the Linux system, open the "terminal", enter the Shell command prompt state, and then, under the "/usr/local/scala/mycode" directory, create a new wordcount subdirectory and place it in "/usr/local/scala Create two new text files word1.txt and word2.txt containing some sentences in the "/mycode/wordcount" directory (you can enter some words in the text file at will, separated by spaces), we will write a Scala program for this directory The two files below are used for word frequency statistics.
Please create a new test.scala file in the "/usr/local/scala/mycode" directory. The following is the Scala program code for word frequency statistics contained in test.scala:
import java.io.File //读文件用的
import scala.io.Source //Souce.fromFile用的
import collection