我想在此 url 上下载 pdf 文件,但没有下载:http://sede.juntaex.es/empleodoc/6e22820d-ec8f-400f-9f80-75c007bdfd43
我在浏览器上复制和粘贴但不起作用。
我使用了这个代码但是不起作用
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(url));
startActivity(intent);
我如何强制下载?
更新: 显然我的意思是下载 pdf 在 android 浏览器中不起作用,也不能通过上面的代码工作。下载可以在我电脑上的浏览器中进行。
我需要强制下载pdf文件。
我想通过单击应用程序中的按钮来下载 pdf
最佳答案
可以在JSP页面中完成我希望它也可以在JAVA中完成,如下所示
DownloadPage.JSP 代码:-
<a href='downloadPdf.jsp?file=FILE.pdf' >Download PDF File</a>
下载Pdf.JSP代码:-
<%@ page import="java.util.*,java.io.*"%>
<%
File f = new File ("E:/PDFfiles/Downloads/" + request.getParameter("file") );
response.setContentType ("application/pdf");
response.setHeader ("Content-Disposition", "attachment; filename=""+request.getParameter("file")+""");
String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
InputStream in = new FileInputStream(f);
ServletOutputStream outs = response.getOutputStream();
int bit = 256;
int i = 0;
try {
while ((bit) >= 0) {
bit = in.read();
outs.write(bit);
}
} catch (IOException ioe) {ioe.printStackTrace(System.out);
}
outs.flush();
outs.close();
in.close();
%>
来源:http://bloggerplugnplay.blogspot.in/2012/05/how-to-create-force-download-link-for.html
关于java - 强制下载PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4651354/