Reputation: 199
I have my data in the form of a CSV file at the following location C:\xyz\data.csv in my system. How can I access this data from the controller of my grails application? Is it possible to do so? If yes, how? Any help would be much appreciated.
Upvotes: 1
Views: 131
Reputation: 711
for reading file (cvs, xml, img ,...) from controller
def csv = grailsAttributes.getApplicationContext().getResource("/data/data.csv").getFile()
try this for your case...
Upvotes: 1
Reputation: 9082
If your Grails application runs on the same system you can access the file like this.
class MyController {
def myAction() {
def myFile = new File('your path')
def content = myFile.text
}
}
If your webapp runs somewhere else (which is most likely your case) you can use the file upload.
Upvotes: 0