def getFile(file:File): Array[File] ={ val files = file.listFiles().filter(! _.isDirectory) .filter(t => t.toString.endsWith(".txt") || t.toString.endsWith(".md")) //此处读取.txt and .md文件 files ++ file.listFiles().filter(_.isDirectory).flatMap(getFile) } val path = new File("G:\\lzp_personal_data\\study_data\\itNote") getFile(path).foreach(println)