Skip to content

Instantly share code, notes, and snippets.

@lawrenceching
Created June 18, 2017 16:51
Show Gist options
  • Save lawrenceching/c46dfc899cc8f18d5b8643f8fcf089a5 to your computer and use it in GitHub Desktop.
Save lawrenceching/c46dfc899cc8f18d5b8643f8fcf089a5 to your computer and use it in GitHub Desktop.
Reading file in Clojure
(ns hello-clojure.core
(:use [clojure.test]))
(require '[
clojure.java.io :as io
] )
(def path "./resources/test/hello.txt")
(defn read-file [path]
(let [file (io/as-file path)]
(if (.exists file)
(slurp file)
)
)
)
(deftest read-content-from-file
(is (= "Hello, World!" (read-file path)))
)
(deftest return-nil-if-read-from-inexist-file
(is (= nil (read-file "./abcde.txt"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment