Compdigitec Labs

« | Home | »

Getting files from sources in Scala

By admin | February 14, 2021

// Java-based ways
getClass.getResource("/html/myfile.html")
println(Source.fromInputStream(getClass.getResourceAsStream("/html/myfile.html")).mkString)

// Scala-native way
// Note: NO LEADING SLASH
println(Source.fromResource("html/myfile.html").getLines.toList)

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: Code | 5 Comments »

5 Responses to “Getting files from sources in Scala”

  1. iTune gift card Says:
    June 14th, 2024 at 18:26

    … [Trackback]

    […] There you can find 55904 more Info to that Topic: compdigitec.com/labs/2021/02/14/getting-files-from-sources-in-scala/ […]

  2. go88 Says:
    June 15th, 2024 at 12:31

    … [Trackback]

    […] Read More on on that Topic: compdigitec.com/labs/2021/02/14/getting-files-from-sources-in-scala/ […]

  3. เทรดทอง Says:
    June 19th, 2024 at 01:46

    … [Trackback]

    […] There you can find 69251 more Info on that Topic: compdigitec.com/labs/2021/02/14/getting-files-from-sources-in-scala/ […]

  4. ข่าวบอล Says:
    June 20th, 2024 at 18:33

    … [Trackback]

    […] Find More Info here on that Topic: compdigitec.com/labs/2021/02/14/getting-files-from-sources-in-scala/ […]

  5. plumbers woodstock ga Says:
    June 21st, 2024 at 18:23

    … [Trackback]

    […] Read More on on that Topic: compdigitec.com/labs/2021/02/14/getting-files-from-sources-in-scala/ […]

Comments