Groovy 无效的文字/长度代码-如何解决此问题?

Groovy 无效的文字/长度代码-如何解决此问题?,groovy,gradle,Groovy,Gradle,我是groovy的新手,我想从jar文件中解压资源。正如蒂姆·耶茨(tim_yates)在这里写道的那样,我是这样尝试的: 我也试过: getClass().getResource('/resources/my.dll').withInputStream { is -> new File("my.dll").withOutputStream { os -> Files.copy(is, os) } } 但是没有成功。我已经检查了是否可用,它是否(是否

我是groovy的新手,我想从jar文件中解压资源。正如蒂姆·耶茨(tim_yates)在这里写道的那样,我是这样尝试的:

我也试过:

getClass().getResource('/resources/my.dll').withInputStream {
    is -> new File("my.dll").withOutputStream {
        os -> Files.copy(is, os)
    }
}
但是没有成功。我已经检查了
是否可用,它是否(
是否可用()
返回914432)

[编辑]

如果我尝试以这种方式复制文件,它将起作用:

new File("C:\\Document.html").withInputStream {
    is -> new File("C:\\Document_Copy.html").withOutputStream {
        os -> os << is
    }
}
新文件(“C:\\Document.html”)。withInputStream{
is->新文件(“C:\\Document\u Copy.html”)。不带输出流{

os->os即使在Groovy中,您也应该始终使用
getResourceAsStream
读取资源文件的内容。如果资源路径(Jar内部)是
resources/my.dll
,并且Jar位于类路径上,则应该可以:

def stream = getClass().classLoader.getResourceAsStream("resources/my.dll")
def file = new File("my.dll")
file.delete()
stream.withStream {
    file << stream
}
def stream=getClass().classLoader.getResourceAsStream(“resources/my.dll”)
def file=新文件(“my.dll”)
file.delete()
顺流而下{
文件
new File("C:\\Document.html").withInputStream {
    is -> new File("C:\\Document_Copy.html").withOutputStream {
        os -> os << is
    }
}
def stream = getClass().classLoader.getResourceAsStream("resources/my.dll")
def file = new File("my.dll")
file.delete()
stream.withStream {
    file << stream
}