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

      

  • 相关阅读:
    POJ 1141 括号匹配 DP
    881. Boats to Save People
    870. Advantage Shuffle
    874. Walking Robot Simulation
    文件操作
    861. Score After Flipping Matrix
    860. Lemonade Change
    842. Split Array into Fibonacci Sequence
    765. Couples Holding Hands
    763. Partition Labels
  • 原文地址:https://www.cnblogs.com/cczhoufeng/p/3109699.html
Copyright © 2011-2022 走看看