在 Gradle 中,我有一个文件存储在 Internet 上,我想访问它。但我不知道如何在 Gradle 中将URLa转换为 a File。我需要将 url 转换为文件,以便我可以将其作为文件传递给任务。这是我到目前为止所拥有的:
allprojects {
afterEvaluate { project ->
String file = new URL('http://techslides.com/demos/samples/sample.json').file
}
}
Run Code Online (Sandbox Code Playgroud)
这绝对不是我想要的。文件变量最终是:demos/samples/sample.json所以看起来它只是从 url 本身获取路径。
我需要将实际sample.json 存储在一个File对象中。如果可能的话,我还希望不必将文件写入本地存储,其他人可以访问它作为安全文件。
执行此操作的最简单方法:
def fileLocation = 'file://techslides.com/demos/samples/sample.json'
def fileURL = new URL(fileLocation)
def remoteFile = new File(fileURL.toURI())
Run Code Online (Sandbox Code Playgroud)
请参阅:文件(URI uri)
替换fileLocation为您的任务的有效值。
| 归档时间: |
|
| 查看次数: |
7214 次 |
| 最近记录: |