Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to instantiate Path object using clojure

since a Path class does not have public constructor ,so path object are created using get factory method in Paths object.

e.g

Path p2 = Paths.get("/home/admin","Migrations","/blog/tables/6-rating.xml");

//or

Path p2 = Paths.get(new URI("file://home/debianaut/Migrations/blog.sakhunzai/tables/6-rating.xml"));

how we can do this in clojure way ?

like image 329
sakhunzai Avatar asked Aug 05 '14 18:08

sakhunzai


1 Answers

user> (java.nio.file.Paths/get "/home/justin" (into-array [".lein" "profiles.clj"]))
#<UnixPath /home/justin/.lein/profiles.clj>

varargs java methods need an array containing all remaining args as their final argument.

The first string outside the array is needed in order for the method dispatch to match the right method.

For completeness, here is an example using a URI (much more straightforward):

user> (java.nio.file.Paths/get (java.net.URI. "file:///home/justin"))
#<UnixPath /home/justin>
like image 181
noisesmith Avatar answered Nov 08 '22 13:11

noisesmith