Where to put a text file in Grails, and how to get the path

前端 未结 4 1056
感动是毒
感动是毒 2020-12-13 09:41

I need to read in a .txt file into a groovy class in order to interrogate it line by line. But I am not sure what folder I put it into in my grails app, and how to get the

4条回答
  •  醉梦人生
    2020-12-13 10:25

    You can put your file under web-app/

    Example:

    web-app/lexicon.txt
    

    And then in your controller or service use grailsApplication:

    class MyService {
        def grailsApplication
        public myMethod() {
            File myFile = grailsApplication.mainContext.getResource("lexicon.txt").file
        }
    }
    

    Hope this helps

提交回复
热议问题