我正在使用itext创建可编辑的pdf并下载它。使用mvn appengine:run
在本地运行时,pdf下载时本地没有任何问题。部署到Google App Engine后,当我尝试下载其抛出
Internal Server 500 Error
Whitelabel Error Page
This application has no explicit mapping /error, so you are seeing this as a fallback.
Sat Nov 11 17:41:57 UTC 2017
There was an unexpected error (type=Internal Server Error, status=500).
/base/data/home/Downloads/file.pdf (No such file or directory)"
以下是供下载的代码,
String home = System.getProperty("user.home");
File file = new File(home+"/Downloads/"+fileName);
// creating pdf code
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename="+fileName);
FileInputStream fis = null;
DataOutputStream os = null;
try
{
response.setHeader("Content-Length", String.valueOf(file.length()));
fis = new FileInputStream(file);
os = new DataOutputStream(response.getOutputStream());
byte[] buffer = new byte[1024];
int len = 0;
while((len = fis.read(buffer)) >= 0)
{
os.write(buffer,0,len);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
fis.close();
os.flush();
os.close();
}
谢谢!