一、
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);
为什么输出的结果不一样??