如何在Groovy中创建一个临时文件?
发布时间:2020-12-14 16:36:57 所属栏目:大数据 来源:网络整理
导读:在Java中存在用于创建临时文件的java.io.File.createTempFile函数。在Groovy中,似乎没有这样的功能,因为File类中缺少这个功能。 (见: http://groovy.codehaus.org/groovy-jdk/java/io/File.html) 有没有一个合理的方式来创建一个临时文件或文件路径在Groo
在Java中存在用于创建临时文件的java.io.File.createTempFile函数。在Groovy中,似乎没有这样的功能,因为File类中缺少这个功能。 (见:
http://groovy.codehaus.org/groovy-jdk/java/io/File.html)
有没有一个合理的方式来创建一个临时文件或文件路径在Groovy无论如何,或者我需要自己创建一个(这是不容易得到正确,如果我没有错误)? 先谢谢你! 解决方法File.createTempFile("temp",".tmp").with { // Include the line below if you want the file to be automatically deleted when the // JVM exits // deleteOnExit() write "Hello world" println absolutePath } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |