如何在下载时获取查看格式的 pdf 文件而不保存或另存为选项。任何人都可以帮助我解决这种情况并提供示例代码。这是我的下载和保存格式的代码。
File f= new File(file);
if(f.exists()){
ServletOutputStream op= response.getOutputStream();
response.reset();
if(check==1){
response.setContentType("application/pdf");
}else{
response.setContentType(content);
}
response.setHeader("Content-disposition","attachment; filename=" +fileName);
byte[] buf = new byte[4096];
int length;
DataInputStream in = new DataInputStream(new FileInputStream(f));
while ((in != null) && ((length = in.read(buf)) != -1)){
op.write(buf,0,length);
}
in.close();
op.flush();
op.close();
}
最佳答案
您需要将代码更改为
response.setHeader("Content-disposition","inline; filename=" +fileName);
关于java - 如何在下载时获取查看格式的 pdf 文件而不保存或另存为选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19291548/