views:

67

answers:

1

I am trying to get the last modified time from a file in Clojure, by executing a Java command. By using java.io.File.lastModified I am supposed to be able to get the UNIX-time, this does not work by execution of the script or in the REPL.

My code is: (java.io.File.lastModified "/home/lol/lolness.txt")

and my error is: java.lang.ClassNotFoundException: java.io.File.lastModified (NO_SOURCE_FILE:24)

(java.io.File.separator) works, however.

EDIT: Clojure version 1.2.0-master-SNAPSHOT Java version OpenJDK 1.6.0

+5  A: 

lastModified is a method of java.io.File objects. To access it in Clojure, use the following syntax:

(.lastModified (java.io.File. "/home/lol/lolness.txt"))

Note that the namespaces clojure.contrib.java-utils (1.1) / clojure.java.io (bleeding edge) provide a function file which makes the creation of java.io.File objects more convenient. Since you're on the bleeding edge, the following should work for you:

(require '[clojure.java.io :as io])
(.lastModified (io/file "/home/lol/lolness.txt"))
Michał Marczyk