问题描述
publicStringxiaz()throwsException{Filefile=newFile("E://in.txt");response.reset();response.setCharacterEncoding("utf-8");response.setContentType("multipart/form-data");StringdownloadFileName="in.txt";response.setHeader("Content-type","application-download");response.setHeader("Content-disposition","attachment;filename="+downloadFileName);intfileLength=(int)file.length();response.setContentLength(fileLength);try{OutputStreamoutputStream=response.getOutputStream();InputStreaminputStream=newFileInputStream(file);byte[]buffer=newbyte[1024];inti=-1;while((i=inputStream.read(buffer))!=-1){outputStream.write(buffer,0,i);}inputStream.close();outputStream.flush();outputStream.close();}catch(Exceptione){e.printStackTrace();}returnnull;}response返回结果Content-disposition:attachment;filename=in.txtContent-Length:15Content-Type:application-download;charset=utf-8Date:Fri,22Aug201408:59:41GMTServer:Apache-Coyote/1.1小弟用的ssh框架
解决方案
解决方案二:
下载不是直接将你的文件的相对地址放到超链接里就行了么?