/**
* <p>功能:下载apk</p>
* @author 周枫
* @date 2013-5-29
* @param
* @return void
*/
public void bagDownloadApk() throws Exception
{
String fileName = "";
String filePath = "";
List<HashMap> list = new ArrayList<HashMap>();
list = teachUpdateService.selectApkInfo();
for (int i = 0; i < list.size(); i++) {
fileName = list.get(i).get("APK_NAME").toString();
filePath = list.get(i).get("APK_PATH").toString();
}
filePath = filePath + fileName;
// 打开指定文件的流信息
java.io.FileInputStream fs = null;
try {
fs = new java.io.FileInputStream(new java.io.File(filePath));
} catch (java.io.FileNotFoundException e) {
e.printStackTrace();
}
// 设置响应头和保存文件名
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\""
+ fileName + "\"");
// 写出流信息
int b = 0;
try {
java.io.PrintWriter out = response.getWriter();
while ((b = fs.read()) != -1) {
out.write(b);
}
fs.close();
out.close();
System.out.println("文件下载完毕.");
} catch (Exception e) {
e.printStackTrace();
System.out.println("下载文件失败!");
} finally {
if(null != fs){
fs.close();
}
}
}