首页 新闻 会员 周边 捐助

javaweb 下载功能 安卓手机默认浏览器不能下载 下载的文件类型为apk

0
悬赏园豆:5 [待解决问题]

  最近在项目里写了个下载功能,在电脑上测试可用。我下载的是apk文件,服务端用的是tomcat.

response.setContentType("application/vnd.android.package-archive") 这个也设置过了。但是手机上访问时,我点下载链接竟然没一点反应。用了安卓手机自带的浏览器 和 qq浏览器 都不能用,只有uc能成功!在网上查查也没找到答案,第一种方法后台是这样写的 

    File _file = new File( request.getSession().getServletContext().getRealPath(Constants.PATH_ANDROIDPN_FILE) + "\\短息接收.apk");
                response.setContentType("application/vnd.android.package-archive");// oper save as 对话框
                response.setCharacterEncoding("GBK");
//                response.setHeader("Content-Disposition", "attachment;" + "filename=" + new String(gg_fjghwd.getShowname().getBytes(), "ISO-8859-1"));
                response.setHeader("Content-Disposition", "attachment;" + "filename=" + new String("大嘴巴.apk".getBytes(),"ISO-8859-1"));
                System.out.println("------1-----");
                
                copyFileToStream(_file, response.getOutputStream());

private void copyFileToStream(File f, OutputStream ostream) throws IOException {
FileInputStream fis = new FileInputStream(f);
byte[] buffer = new byte[BUFFER_SZ];
try {
while (true) {
int bytesReceived = fis.read(buffer);
if (bytesReceived < 1) {
break;
}


ostream.write(buffer, 0, bytesReceived);
}
System.out.println(ostream);
} finally {
fis.close();
}
}

但是用第一种方法后台会报错

ClientAbortException: java.io.IOException
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)

最后没法了我这样写<a href="<%=strHttp %>${ctx}/uploads/DZB.apk" >1安卓系统</a> 可是还是不能下载!大家帮忙看看
jackonline的主页 jackonline | 菜鸟二级 | 园豆:201
提问于:2012-10-10 17:10
< >
分享
所有回答(2)
0

前台现在连接写的有问题,忘记写tagert

jackonline | 园豆:201 (菜鸟二级) | 2012-11-09 10:28
0

怎么解决的呀?

it鱼说 | 园豆:202 (菜鸟二级) | 2017-10-15 15:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册