java學習

          java學習

           

          文件的下載

                 
                          File f = new  File("c://a.txt");            
                              BufferedInputStream bis =new BufferedInputStream(new FileInputStream(f));
                              byte[]  buffer = new  byte[1024];
                              response.setContentType("application/octet-stream");
                              //定義下載文件的名字
                              String a = new String(z.getZiname().getBytes("utf-8"),"iso8859-1");
                        
                              response.setHeader("Content-Disposition", "attachment; filename=\"" + a+"c://a.txt".substring("c://a.txt".lastIndexOf(".")) + "\"");
                              OutputStream os = response.getOutputStream();
                              int  len = -1;
                              while((len=bis.read(buffer))!=-1){
                                  os.write(buffer, 0, len);
                              }
                              os.flush();
                              os.close();
                              bis.close();                
                     

          posted on 2013-03-20 10:32 楊軍威 閱讀(148) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阿城市| 峨边| 阜新市| 白水县| 建阳市| 区。| 台州市| 平顶山市| 大厂| 天气| 买车| 教育| 攀枝花市| 新疆| 广宗县| 白水县| 忻城县| 万源市| 邹平县| 新疆| 昔阳县| 岳普湖县| 桃园县| 花垣县| 肃北| 远安县| 丰台区| 双峰县| 静宁县| 太湖县| 那坡县| 伊通| 海阳市| 桑植县| 大姚县| 聂拉木县| 甘肃省| 明星| 巩留县| 米林县| 桂平市|