如何访问Grails中的文件系统文件夹

时间:2015-04-02 19:05:39

标签: grails

我将一些文档上传到uploadFolder C:/ upload config path

environments {
    development {
        uploadFolder = "C:/upload/"
    }
    production {
        uploadFolder = "C:/upload/"

    }
    test {
        uploadFolder = "C:/Users/"
    }
}

并将其存储在控制器中

documentInstance.fullPath = grailsApplication.config.uploadFolder + documentInstance.filename

如何访问Grails中C:/ upload /文件中的文档?

1 个答案:

答案 0 :(得分:0)

您在Grails中访问文件的方式与在普通Web应用程序中执行此操作的方式没有区别。如果您的路径是绝对路径,您可以这样做

def path = grailsApplication.config.uploadFolder + documentInstance.filename
File file = new File(path)

或列出上传文件夹中的所有文件

Folder dir = new File(grailsApplication.config.uploadFolder)
dir.eachFile() {File file ->  doSomething..}