做流程导出时的两个疑问,关于HttpServletResponse和用java读取文件。

一、

rep.setContentType("application/zip");
   rep.setHeader("Content-Disposition", "attachment; filename=/""
     + new String((processDefName + ".zip").getBytes(),
       "ISO-8859-1") + "/"");

之后再用out.write();把一个文件写出去。

这样做,后面返回的jsp页面的内容到底会不会被写入到response中,从而损坏了文件?我的试验结果不会,但据说应该返回一个空白的页面,以保证文件不会损坏。

         两种读取读取文件的方式为什么读的文件不一样??

BufferedReader in = new BufferedReader(new FileReader(maindir+".zip"));
   StringBuffer sb=new StringBuffer();
   String s=new String();
   while((s=in.readLine())!=null){
    sb.append(s);
    sb.append("/n");
   }
   in.close();
   byte[] data=sb.toString().getBytes();

   out.write(data);

另一种方式为

in = new FileInputStream(new File(maindir + ".zip"));
   int b;
   out = rep.getOutputStream();
   while ((b = in.read()) != -1) {
    out.write(b);
为什么输出的结果不一样??

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值