Most times we want to work with an external file, especially when it involves reading text. So, let's learn how to read a file in Clojure. We will be making use of the slurp
method. The slurp
method is used to read a file.
slurp filename
filename
: The slurp
method receives a single parameter which is the file name.The slurp
method returns a string from a file.
Hello from Educative..
The above code example illustrates how we use the slurp
method to read a text file.
func
.file1
, and then we use the slurp
method on the file.txt
file. Note: We have the
main.clj
, which is our code, and thefile.txt
, which is the file we are reading from.
println
method to print out the string returned by the slurp
method.func
.RELATED TAGS
CONTRIBUTOR
View all Courses