java.io.IOException: Permission denied while creating new file from Tomcat in Grails -
i have grails application deployed on tomcat 7. here code fragment tries create new file:
def path = "/var/csvs" + file.fileitem.filename def fileinputstream = file.inputstream file f = new file(path) if (!f.exists()) { f.createnewfile() }
i exception:
permission denied. stacktrace follows: java.io.ioexception: permission denied @ java.io.file.createnewfile(file.java:1006)
i have given rwx permission tomcat7(the user under tomcat running). why not able create new file? "/var/csvs" trying create file relative tomcat webapps directory? if yes how should create file @ /var/csvs (where csvs folder have created under /var)?
edit:
here permissions on /var/csvs folder:
root@myip:/# ls -ld /var/csvs drwxrwxrwx 2 tomcat7 tomcat7 4096 jun 3 15:44 /var/csvs
so tomcat7 owner of directory , mode 777
shouldn't code
def path = "/var/csvs/" + file.fileitem.filename // notice trailing fwd slash
otherwise you're trying write /var
directory.
Comments
Post a Comment