slurp works well, however, it reads the file in as a single string. The result may not be readily useable depending on what you are doing. I read in text files using clojure.java.io functions plus the core function line-seq. What you get is a sequence whose elements are the individual lines of the file. Then you can apply the power of the Clojure sequence library functions to the problem you are trying to solve. This gets the text file directly to a data structure which is easily processed. Here's a quick example function: (use 'clojure.java.io) (defn grab-file [file-path] (with-open [text-file-reader (reader file-path)] (do-all (line-seq text-file-reader)))) This returns a sequence of strings. The file-path parameter is a string which is the path to the file. Other functions in clojure.java.io are very useful for dealing with files. Note the reader function is wrapped in a with-open function to make sure it is properly closed. Regards, Greg
On Friday, February 1, 2013 7:17:43 AM UTC-5, Roger75 wrote: > I'd like to read a txt file using clojure. How do I do that? Any examples? -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.