細心!用心!耐心!

          吾非文人,乃市井一俗人也,讀百卷書,跨江河千里,故申城一游; 一兩滴辛酸,三四年學業,五六點粗墨,七八筆買賣,九十道人情。

          BlogJava 聯系 聚合 管理
            1 Posts :: 196 Stories :: 10 Comments :: 0 Trackbacks
          ?1 package ?com.stt.doss.common.util.upload;
          ?2
          ?3 import ?java.io.BufferedOutputStream;
          ?4 import ?java.io.FileInputStream;
          ?5 import ?java.io.FileNotFoundException;
          ?6 import ?java.io.IOException;
          ?7 import ?java.io.UnsupportedEncodingException;
          ?8
          ?9 import ?javax.servlet.http.HttpServletResponse;
          10
          11 import ?com.stt.doss.util.Convertor;
          12
          13 /**
          14 ?*?<p>
          15 ?*?Title:
          16 ?*?</p>
          17 ?*?<p>
          18 ?*?Description:處理下載文件工具類
          19 ?*?</p>
          20 ?*?<p>
          21 ?*?Copyright:?Copyright?(c)?2006
          22 ?*?</p>
          23 ?*?<p>
          24 ?*?Company:?stt
          25 ?*?</p>
          26 ?*?
          27 ?*? @author ?william
          28 ?*? @version ?1.0
          29 ? */

          30 public ? class ?DownloadHelper? {
          31
          32 ???? /**
          33 ?????*?下載文件
          34 ?????*?
          35 ?????*? @param ?response
          36 ?????*? @param ?fileName
          37 ?????*? @param ?filePath
          38 ????? */

          39 ???? public ? static ? void ?downloadFile(HttpServletResponse?response,?String?fileName,
          40 ????????????String?fileAllPath)? {
          41
          42 ????????StringBuffer?sb? = ? new ?StringBuffer( 150 );
          43 ????????sb.append( " attachment;??filename= " );
          44 ????????sb.append(Convertor.iso2gbk(fileName));
          45
          46 ???????? if ?( null ? != ?fileAllPath? && ?fileName? != ? null )? {
          47 ????????????FileInputStream?fis? = ? null ;
          48 ????????????BufferedOutputStream?bos? = ? null ;
          49 ???????????? try ? {
          50 ????????????????response
          51 ????????????????????????.setContentType( " application/x-msdownload;charset=GB2312 " );
          52
          53 ????????????????response.setHeader( " Content-Disposition " ,? new ?String(sb
          54 ????????????????????????.toString().getBytes(),? " ISO-8859-1 " ));
          55 ????????????????fis? = ? new ?FileInputStream(Convertor.iso2gbk(fileAllPath));
          56 ????????????????bos? = ? new ?BufferedOutputStream(response.getOutputStream());
          57 ???????????????? byte []?buffer? = ? new ? byte [ 2048 ];
          58 ???????????????? while ?(fis.read(buffer)? != ? - 1 )? {
          59 ????????????????????bos.write(buffer);
          60 ????????????????}

          61 ????????????????bos.write(buffer,? 0 ,?buffer.length);
          62 ???????????????? // ?fis.close();
          63 ???????????????? // ?bos.close();
          64 ????????????}
          ? catch ?(UnsupportedEncodingException?e)? {
          65 ???????????????? // ?TODO?Auto-generated?catch?block
          66 ????????????????e.printStackTrace();
          67 ???????????????? throw ? new ?RuntimeException();
          68 ????????????}
          ? catch ?(FileNotFoundException?e)? {
          69 ???????????????? // ?TODO?Auto-generated?catch?block
          70 ????????????????e.printStackTrace();
          71 ???????????????? throw ? new ?RuntimeException();
          72 ????????????}
          ? catch ?(IOException?e)? {
          73 ???????????????? // ?TODO?Auto-generated?catch?block
          74 ????????????????e.printStackTrace();
          75 ???????????????? throw ? new ?RuntimeException();
          76 ????????????}
          ? finally ? {
          77 ???????????????? try ? {
          78 ???????????????????? if ?(fis? != ? null )? {
          79 ????????????????????????fis.close();
          80 ????????????????????}

          81 ???????????????????? if ?(bos? != ? null )? {
          82 ????????????????????????bos.close();
          83 ????????????????????}

          84 ????????????????}
          ? catch ?(IOException?e)? {
          85 ???????????????????? // ?TODO?Auto-generated?catch?block
          86 ????????????????????e.printStackTrace();
          87 ???????????????????? throw ? new ?RuntimeException();
          88 ????????????????}

          89
          90 ????????????}

          91 ????????}

          92
          93 ????}

          94 }

          95
          posted on 2007-03-16 15:26 張金鵬 閱讀(198) 評論(0)  編輯  收藏 所屬分類: core java中的一些數據結構的處理
          主站蜘蛛池模板: 繁昌县| 连平县| 新平| 信宜市| 博客| 白城市| 固阳县| 股票| 恩平市| 开平市| 辽阳县| 耿马| 沂源县| 贺兰县| 都昌县| 大关县| 长泰县| 榆林市| 哈尔滨市| 彩票| 太湖县| 东兴市| 嘉定区| 固始县| 当阳市| 松潘县| 平凉市| 曲周县| 遵化市| 西青区| 台南县| 岳普湖县| 巴林左旗| 浦江县| 娱乐| 岑巩县| 南安市| 晋中市| 和硕县| 衡阳县| 阿克|