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. BAU Diyala Says:
    January 17th, 2025 at 20:55

    … [Trackback]

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

  2. ทดลองเล่นสล็อต PG SLOT Says:
    January 17th, 2025 at 23:21

    … [Trackback]

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

  3. สล็อตเว็บตรง ทุนน้อยโบนัสแตกโหด ถอนได้ไม่อั้น Says:
    January 19th, 2025 at 02:31

    … [Trackback]

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

Comments