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)
最后没法了我这样写1安卓系统 可是还是不能下载!大家帮忙看看