How to read files from resources folder in Scala?

前端 未结 6 938
渐次进展
渐次进展 2020-11-29 16:37

I have a folder structure like below:

- main
-- java
-- resources 
-- scalaresources
--- commandFiles 

and in that folders I have my files

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 16:50

    import scala.io.Source
    
    object Demo {
    
      def main(args: Array[String]): Unit = {
    
        val ipfileStream = getClass.getResourceAsStream("/folder/a-words.txt")
        val readlines = Source.fromInputStream(ipfileStream).getLines
        readlines.foreach(readlines => println(readlines))
    
      }
    
    }
    

提交回复
热议问题