posts - 54,  comments - 1,  trackbacks - 0
           /**
            * 實現(xiàn)下載
            *
            * 
          @param response
            * 
          @param headName: 默認(rèn)文件名
            * 
          @param fileUrl :目標(biāo)文件URL
            * 
          @throws Exception
            *
          */

           
          public void downLoad(HttpServletResponse response, String headName,
             String fileUrl) 
          throws Exception {

            
          if (headName.endsWith(".jpg"|| (headName.endsWith(".gif"))) {
             
          //no need setting content type and header
            }
           else if (headName.endsWith(".txt")) {
             response.setContentType(
          "text;charset=GB2312");
             response.setHeader(
          "Content-disposition""attachment; filename="
               
          + headName);
            }
           else {
             response.setContentType(
          "application/doc;charset=GB2312");
             response.setHeader(
          "Content-disposition""attachment; filename="
               
          + headName);
            }


            String fileURL 
          = fileUrl;
            
          if (fileURL == null)
             
          return;

            
          try {
             File file 
          = new File(fileUrl);
             FileInputStream bis 
          = new FileInputStream(file);
             OutputStream bos 
          = response.getOutputStream();

             
          byte[] buff = new byte[1024];
             
          int readCount = 0;
             
          int i = 0;
             readCount 
          = bis.read(buff);
             
          while (readCount != -1{
              bos.write(buff, 
          0, readCount);
              readCount 
          = bis.read(buff);
             }

             
          if (bis != null)
              bis.close();
             
          if (bos != null)
              bos.close();

            }
           catch (Exception e) {
             e.printStackTrace();
             
          throw e;
            }

           }



          posted on 2005-11-24 17:25 ZhuJun 閱讀(346) 評論(0)  編輯  收藏 所屬分類: 開發(fā)手記

          蜀中人氏,躬耕于珠海

          <2005年11月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          常用鏈接

          留言簿(2)

          隨筆分類(71)

          隨筆檔案(54)

          博客

          文檔

          站點

          論壇

          搜索

          •  

          積分與排名

          • 積分 - 51003
          • 排名 - 976

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 枣庄市| 莱阳市| 那坡县| 静乐县| 古浪县| 乐陵市| 舟曲县| 宁都县| 个旧市| 米泉市| 启东市| 杭锦旗| 南城县| 乐安县| 南澳县| 惠州市| 赣州市| 泰来县| 农安县| 清河县| 佛教| 日喀则市| 永善县| 卢氏县| 铜山县| 富源县| 上杭县| 长子县| 江油市| 北川| 贵港市| 蒙城县| 醴陵市| 黄大仙区| 巴塘县| 乃东县| 龙里县| 囊谦县| 西城区| 巍山| 西乌|