简体   繁体   English

clojure.java.io ClassNotFoundException

[英]clojure.java.io ClassNotFoundException

I am trying to run the following program on my Mac:我正在尝试在我的 Mac 上运行以下程序:

(ns clojure.examples.hello
   (:gen-class))
(require ‘clojure.java.io’)
(defn Example []
   (.exists (file "Example.txt")))
(Example)

I do this wih the following command:我使用以下命令执行此操作:

clojure Exists.clj

But this gives me the following error:但这给了我以下错误:

Syntax error (ClassNotFoundException) compiling at (Exists.clj:5:1).
‘clojure.java.io’

How can I go about including the clojure.java.io class?我怎样才能把go包括clojure.java.io class?

Here is how you would normally write this in a source code file:以下是您通常如何在源代码文件中编写它:

(ns tst.demo.core
  (:require [clojure.java.io :as io]) ; proper form, but not used anywhere
  (:import [java.io File]))

(println (spit "demo.txt" "stuff happens"))
(println (slurp "demo.txt"))
(println (.exists (java.io.File. "./demo.txt"))) ; will work w/o `:import` above
(println (.exists (File. "./demo.txt"))) ; requires `:import` declaration above

with results:结果:

(spit "demo.txt" "stuff happens")        => nil
(slurp "demo.txt")                       => "stuff happens"
(.exists (java.io.File. "./demo.txt"))   => true
(.exists (File. "./demo.txt"))           => true

Note that using the :require keyword in a ns form requires different syntax and quoting than using the (require...) function call.请注意,在ns表单中使用:require关键字需要与使用(require...) function 调用不同的语法和引用。

If you are typing these lines into a REPL, you may do something like:如果您将这些行输入到 REPL 中,您可以执行以下操作:

demo.core=> (ns demo.core)
nil
demo.core=> (require '[clojure.java.io :as io])   ; function-call version
nil
demo.core=> (spit "demo.txt" "stuff happens")
nil
demo.core=> (println (slurp "demo.txt"))
stuff happens
nil

You may find this template project helpful in getting started.您可能会发现此模板项目有助于入门。 Also be sure to check out the list of documentation sources, esp.还要确保查看文档来源列表,尤其是。 the Clojure CheatSheet! Clojure 备忘单!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Clojure:clojure.java.io/resource如何加载文件? - Clojure: How does clojure.java.io/resource load file? 要编写下载器,请使用Clojure.java.io还是Java的io api? - To write a downloader, Clojure.java.io or Java's io api? 我如何使用 lein exec 要求 clojure.java.io? - How do I require clojure.java.io with lein exec? 为什么在这种情况下clojure.java.io/resource不起作用? - Why doesn't clojure.java.io/resource work in this case? 没有方法的实现::协议的as-file:#'clojure.java.io /为类发现的强制:clojure.lang.PersistentVector - No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.PersistentVector 没有实现方法:: make-reader of protocol:#'clojure.java.io / IOFactory for class:nil - No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil Clojure Clostache错误-没有实现方法::make-reader of protocol:#'clojure.java.io / IOFactory为类nil找到 - Clojure Clostache error - No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil clojure的读取文件结构,即with-open和clojure.java.io/reader,是否足够频繁访问? - Is clojure's read file structure, i.e. with-open and clojure.java.io/reader, efficient enough for frequent access? Clojure lein uberjar:java.lang.ClassNotFoundException - Clojure lein uberjar: java.lang.ClassNotFoundException Clojure defrecord序列化ClassNotFoundException - Clojure defrecord serialization ClassNotFoundException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM