81,092
社区成员
发帖
与我相关
我的任务
分享
<a href="http://192.168.2.106:8080/file/pp.pdf">打开文件</a>
ServletOutputStream out= response.getOutputStream();
respost.setContentType("application/pdf ");
respose.setHeader( "Content-disposition", "attachment;filename=" +"pp.pdf");//别人下载时的文件名。
String fileURL = "http://192.168.2.106:8080/file/pp.pdf";
URL url = new URL(fileURL);
//*********************************************************
//如果需要通过防火墙,要考虑URL 链接
//*********************************************************
BufferedInputStream bis = new BufferedInputStream(url.openStream());
//完成上述操作,就只要简单地将 InputStream 中的字节,写入到 servlet 的输出流 OutputStream 中:
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
// Simple read/write loop.
while(-1 != (bytesRead = bis.read(buff,0,buff.length))){
bos.write(buff, 0, bytesRead);
}