0
我有一個要求,允許用戶輸入服務器路徑和文件名並下載文件。
我用下面的代碼爲服務宗旨:OAF - 從服務器下載文件
HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();
File fileToDownload = null;
try
{
fileToDownload = new File(filePath);
}
catch (Exception e)
{
throw new OAException("Invalid File Path or file does not exist.");
}
response.setContentType(fileType);
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setContentLength((int)fileToDownload.length());
InputStream in = null;
ServletOutputStream outs = null;
try
{
outs = response.getOutputStream();
in = new BufferedInputStream(new FileInputStream(fileToDownload));
int ch;
while ((ch = in.read()) != -1)
{
outs.write(ch);
}
}catch (IOException e)
{
// TODO
e.printStackTrace();
}finally
{
try
{
outs.flush();
outs.close();
if (in != null)
{
in.close();
}
}catch (Exception e)
{
e.printStackTrace();
}
}
的問題與此是,超過48KB更大的任何文件,下載時附加在其中一個額外的行。
使用開發人員指南中提到的messageDownload項目的方法不夠清楚。它提到了一個VO。什麼應該是這個VO的查詢?我們如何在此表中插入文件以用於此VO?
請提出解決方案。