Hi, can you give me an example on how to read a file from disk?
Can't find anything in the tutorial or the standard library.
Thanks
Found this https://github.com/roc-lang/roc/blob/main/examples/cli/file.roc
That is a small app that does a mix of file io
https://github.com/roc-lang/roc/blob/main/examples/cli/file.roc#L29
is reading a file
Docs here: https://www.roc-lang.org/packages/basic-cli/File
I'm a bit surprised that isn't linked in the tutorial
Alright, so far I have this
main : Task {} []
main =
content <- readFile "day01/sample" |> await
Stdout.line "I read the file back. Its contents: \"\(content)\""
readFile : Str -> Task Str []
readFile = \filePath ->
task =
File.readUtf8 (Path.fromStr filePath)
attempt task \result ->
when result is
Err _ -> Task.succeed "Error"
Ok content -> Task.succeed content
Next step is to see how I can pipe this into somethig else
Last updated: Jul 06 2025 at 12:14 UTC