Created
June 18, 2017 16:51
-
-
Save lawrenceching/c46dfc899cc8f18d5b8643f8fcf089a5 to your computer and use it in GitHub Desktop.
Reading file in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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