io流求助
HttpServletRequest请求的时候,如何把一个流输出至访问的请求地址,如:我要像访问的地址写一个文件,怎样写它的路径
------解决方案--------------------是想把文件从页面传到服务器呢,还是想在后台服务器跳转过程中实现文件传递?
------解决方案--------------------public void download(HttpServletRequest request,
HttpServletResponse response) throws Exception {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
request.setCharacterEncoding("UTF-8");
response.setContentType("application/x-msdownload;");
File file = new File("xxxxx");//获取你要输出的文件
String fileName = file.getName();
response.setHeader("Content-disposition", "attachment; filename="
+ fileName);
response.setHeader("Content-Length", String.valueOf(file.length()));
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[1024];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
logger.error("读取需下载的文件失败", e);
throw new IllegalAccessError("读取需下载的文件失败");
} finally {
try{
bis.close();
bos.close();
}catch(
IOException e){
e.printStack();
}finally{
bis = null;
bos = null;
&n