假设我的clojure项目中有两个文件,一个是clj,另一个是txt。 有没有办法从clj文件中知道txt文件的路径(作为字符串)?
有:
(System/getProperty "user.dir")要么
(-> (java.io.File. ".") .getAbsolutePath)但是这给了当前目录。 包含clj文件的代码,其中包含代码。但如何知道txt文件的路径? 目的是从clj文件写入这个txt文件。
谢谢。
Assume there is two files inside my clojure project, one clj and the other is txt. Is there a way to know the path (as a string) of the txt file from the clj file?
There is:
(System/getProperty "user.dir")or
(-> (java.io.File. ".") .getAbsolutePath)But this gives where the current directory. The one that includes the clj file, the one the code is written in. But how to know the path of the txt file? The purpose is to write into this txt file from the clj file.
Thank you.
最满意答案
在Java中,因此Clojure可以在CLASSPATH上找到文件。 例如,在Java中,通常将诸如log4j.properties之类的东西放在CLASSPATH的顶部(例如,在classes目录中),然后可以使用以下方法在Clojure(或Java)代码中引用该文件:
(java.io.File. "log4j.properties")您是否正在使用Leiningen并运行您的应用程序? 如果是这样,您可以在顶层创建一个目录并将文件放在那里。 例如,如果你有一个配置文件,你可以有一个带有属性文件的“conf”目录:
my-lein-proj$ ls conf doc project.clj README.md src target test假设你将一个myproj.conf文件放在conf目录中,并且你想在你的Clojure代码中读取它。 然后你可以做:
(slurp "conf/myproj.conf")In Java and therefore Clojure you can find files on the CLASSPATH. For example, in Java it is common to put things like log4j.properties at the top of your CLASSPATH (e.g., in the classes directory) and then you can reference the file in your Clojure (or Java) code with:
(java.io.File. "log4j.properties")Are you using and running your app with Leiningen? If so, you can create a directory at the top level and put files there. For example, if you have a config file you can have a "conf" dir with a properties files:
my-lein-proj$ ls conf doc project.clj README.md src target testSuppose you put a myproj.conf file in the conf directory and you want to read from it in your Clojure code. Then you can just do:
(slurp "conf/myproj.conf")更多推荐
发布评论