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 | 3 Comments »

3 Responses to “Getting files from sources in Scala”

  1. https://www.happymod.net.br/ Says:
    May 31st, 2021 at 15:05

    … [Trackback]

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

  2. facebook full site login Says:
    June 7th, 2021 at 04:59

    … [Trackback]

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

  3. eBay music coupon Says:
    June 16th, 2021 at 03:57

    … [Trackback]

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

Comments