I had a file that was not encoded using the default file encoding so I
modified slurp to accept an optional encoding parameter.

(defn slurp
  "Reads the file named by f into a string and returns it. Uses the given
encoding
  when opening the file."
  ([#^String f encoding]
    (with-open r (if encoding
                   (new java.io.BufferedReader (new
java.io.InputStreamReader(new java.io.FileInputStream f), encoding))
                   (new java.io.BufferedReader (new java.io.FileReader f)))
      (let [sb (new StringBuilder)]
        (loop [c (. r (read))]
          (if (neg? c)
            (str sb)
             (do
                (. sb (append (char c)))
                (recur (. r (read)))))))))
  "Reads the file named by f into a string and returns it. Uses the default
encoding
  when opening the file."
  ([#^String f] (slurp f nil)))

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to