[英]Groovy File List behaviour for prefix 'file:'
Seems that under recent groovy, the java File object knows that directory paths specified starting with a 'file:' prefix exist, but won't list files from them. 似乎在最近的情况下,java File对象知道存在以'file:'前缀开头的指定目录路径,但是不会列出其中的文件。 Here's a concise example from groovyConsole:
这是来自groovyConsole的简洁示例:
File f1 = new File("/Users/michael/input")
println "f1 exists: ${f1.exists()}"
println "f1 list: ${f1?.listFiles()}"
File f2 = new File("file:/Users/michael/input")
println "f2 exists: ${f2.exists()}"
println "f2 list: ${f2?.listFiles()}"
f1 listFiles() works fine, f2 listFiles returns an empty list. f1 listFiles()工作正常,f2 listFiles返回一个空列表。
I encountered this debugging why spring-integration (upgraded to 4.0.3) suddenly stopped working with grails (upgraded to 2.4.3). 我遇到了这个调试,为什么spring-integration(升级到4.0.3)突然停止使用grails(升级到2.4.3)。
The spring-integration sample code uses the 'file:' prefix. spring-integration示例代码使用“ file:”前缀。 That code works fine under maven/java builds, but add that same sample code to a vanilla grails app and it no longer works.
该代码在maven / java构建下可以正常工作,但是将相同的示例代码添加到vanilla grails应用中,不再起作用。
Any explanation? 有什么解释吗?
As far as I can tell Groovy doesn't do any magic when constructing a new File
. 据我所知,Groovy在构造一个新
File
时没有做任何魔术。 This is standard JDK behavior. 这是标准的JDK行为。 To use
file:
you must pass an URI
to new File(...)
and not a String
. 要使用
file:
您必须将URI
传递给new File(...)
而不是String
。
new File("/Users/nobody/Desktop").absolutePath
===> /Users/nobody/Desktop
new File("file:/Users/nobody/Desktop").absolutePath
===> /Users/nobody/Development/Grails/String/file:/Users/nobody/Desktop
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this is the path to my grails test project
new File("file:/Users/nobody/Desktop".toURI ()).absolutePath
===> /Users/nobody/Desktop
Maybe you have a file named file:/Users/michael/input
(including the "file:") in your working directory. 也许您的工作目录中有一个名为
file:/Users/michael/input
的文件(包括“ file:”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.