简体   繁体   中英

Java : cannot create a file, write access denied

I am installing my webapp(J2EE on tomcat7) on a Ubuntu server.

In my webapp, on my dev pc, I am creating a text file :

File file = new File("VE_EXPORT.TXT");          
FileWriter writer;  
writer = new FileWriter(file, true);
printer.write(necr+jnal+datp+dath+npie+cptg+libe+mont+codc+npoint+codeana+libCompte+"O"+newLine);
printer.close();            
FileInputStream fileInputStream = new FileInputStream(file);
response.reset();
response.setContentType("application/octet-stream");
response.setContentLength((int) (file.length()));
response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
OutputStream output = response.getOutputStream();
IOUtils.copyLarge(fileInputStream, output);
file.delete();
output.flush();

It works fine.
But on the ubuntu server I have a 'permission denied'.
Is there a way not to have this error?
Do I need to do a new file if I just need to flush the output?
Or a way to configure the ubuntu server in order to allow java (or tomcat7 or else) to create the file?

Thanks.

使用chmod获得写访问权限。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM