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 杨军威 阅读(135) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜