zoukankan      html  css  js  c++  java
  • java流下载 东师理想

    /**
    	 * <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();
    			}
    		}
    	}
    

      

  • 相关阅读:
    terminal下历史命令自动完成功能history auto complete
    Shell中while循环的done 后接一个重定向<
    python 链接hive
    shell 学习基地
    c++ 获取本地ip地址
    c++ 如何实现,readonly
    c++ 语法
    c++ 信号量
    vim插件介绍
    c++ memset 函数 及 坑
  • 原文地址:https://www.cnblogs.com/cczhoufeng/p/3109699.html
Copyright © 2011-2022 走看看