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

184 Responses to “Getting files from sources in Scala”

  1. EMINENT Says:
    November 21st, 2022 at 23:50

    playful and amusing

  2. EMINENT Says:
    November 21st, 2022 at 23:52

    SUCCESSFULL

  3. EMINENT Says:
    November 21st, 2022 at 23:53

    unconditional commitment

  4. EMINENT Says:
    November 21st, 2022 at 23:54

    charming

  5. EMINENT Says:
    November 21st, 2022 at 23:54

    having knowledge

  6. EMINENT Says:
    November 21st, 2022 at 23:55

    clever and funny

  7. EMINENT Says:
    November 21st, 2022 at 23:56

    remarkable in performance, execution or design

  8. dany Says:
    November 26th, 2022 at 09:53

    too secure

  9. dany Says:
    November 26th, 2022 at 09:58

    big pass

  10. dany Says:
    November 26th, 2022 at 10:00

    too sweet

  11. dany Says:
    November 26th, 2022 at 10:05

    highly wild

  12. dany Says:
    November 26th, 2022 at 10:07

    well capture

  13. dany Says:
    November 26th, 2022 at 10:09

    best saviour

  14. dany Says:
    November 26th, 2022 at 10:12

    nice base

  15. dany Says:
    November 26th, 2022 at 10:14

    too rare

  16. dany Says:
    November 26th, 2022 at 10:16

    on hanging

  17. dany Says:
    November 26th, 2022 at 10:17

    on flight

  18. dany Says:
    November 26th, 2022 at 10:21

    big voom

  19. dany Says:
    November 26th, 2022 at 10:24

    nice ending

  20. dany Says:
    November 26th, 2022 at 10:26

    nice singing

  21. garmin-france.com Says:
    November 27th, 2022 at 18:15

    … [Trackback]

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

  22. dany Says:
    November 29th, 2022 at 11:58

    one secure

  23. dany Says:
    November 29th, 2022 at 13:09

    two pass

  24. dany Says:
    November 29th, 2022 at 13:52

    three sweet

  25. dany Says:
    November 29th, 2022 at 14:41

    four wild

  26. dany Says:
    November 29th, 2022 at 15:08

    five capture

  27. dany Says:
    November 29th, 2022 at 19:28

    six saviour

  28. dany Says:
    November 29th, 2022 at 20:02

    seven base

  29. dany Says:
    November 29th, 2022 at 20:15

    eight rare

  30. dany Says:
    November 29th, 2022 at 20:45

    nine hanging

  31. dany Says:
    November 29th, 2022 at 20:53

    ten flight

  32. dany Says:
    November 29th, 2022 at 20:59

    eleven voom

  33. dany Says:
    November 29th, 2022 at 21:18

    twelve ending

  34. dany Says:
    November 29th, 2022 at 21:29

    thirteen singing

Comments