… And Back to Clojure

To see how we can get at the wonders of Java from Clojure, let’s reach for every programmer’s favorite abstraction, the file. Java comes packaged with a handy class for representing files, namely java.io.File. According to the documentation for java.io.File, we can create an instance by passing in a string, the path to the file. To create a new instance of a Java class using Clojure’s interoperation facilities—interop for short—we use the classname with a dot on the end in the lead-off spot in the expression:

 (​def​ authors (java.io.File. ​"authors.txt"​))

The preceding code will create a new instance of java.io.File, calling the constructor along the way, and return that instance—which represents ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.