ciao a tutti.
in una servlet che passa un file per il download ho questo codice:
codice:String path //percors del file da passare al browser String type = //mimetype if (type != null) type = "application/x-download"; response.setHeader("Content-Disposition", "attachment; filename=" + path.substring(path.lastIndexOf(File.separator)+1)); response.setContentType(type); ServletOutputStream out = response.getOutputStream(); BufferedInputStream in = null; try { in = new BufferedInputStream(new ZipInputStream(new FileInputStream(path))); }catch(Exception e){ logger.error(e.getLocalizedMessage()); } try{ if (in != null) { while (in.available()>0){ out.write(in.read()); } in.close(); out.close(); } }catch(Exception e){ logger.error(e.getLocalizedMessage()); }
il problema e- che in.available() non sembra fare il suo mestiere, o meglio, il while va in loop e continua a spararmi un stream. ho provato a controlalre su una variabile int.
ma mi legge solo una volta prima di uscire dal while...codice:int d = 0; while (d>-1){ d = in.read(); out.write(d); }
consigli?![]()




Rispondi quotando