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.
slurpmethod receives a single parameter which is the file name.
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.
file1, and then we use the
slurpmethod on the
Note: We have the
main.clj, which is our code, and the
file.txt, which is the file we are reading from.
printlnmethod to print out the string returned by the
View all Courses