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

      

  • 相关阅读:
    牛客 小a与星际探索 bfs
    gear gym 思维题
    dp Surf
    P1280 尼克的任务
    Codeforces Round #539 (Div. 2) C. Sasha and a Bit of Relax
    Codeforces Round #542 C. Connect 搜索
    Layui 文件上传 附带data数据
    Layui 隐藏左侧菜单
    Layui 关闭当前标签页
    Layui Iframe页面间 方法的相互调用
  • 原文地址:https://www.cnblogs.com/cczhoufeng/p/3109699.html
Copyright © 2011-2022 走看看