获取网站资源 getResourceAsStream

时间:2014-05-16 04:41:11   收藏:0   阅读:312
bubuko.com,布布扣
 1     获取网站资源(重点)
 2 public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
 3         // 获取网站对象
 4         ServletContext context = this.getServletContext();
 5         // 获取网站中的静态资源
 6         InputStream in = context.getResourceAsStream("/123.bmp");
 7         // 获取输出流
 8         FileOutputStream out = new FileOutputStream(new File("d:/123.bmp"));
 9         // 边读 边写
10         byte[] bs  = new byte[1024];
11         int len = 0;
12         while((len = in.read(bs)) != -1){
13             out.write(bs, 0, len);
14             out.flush();
15         }
16         // 释放资源
17         in.close();
18         out.close();
19     }
bubuko.com,布布扣

 

获取网站资源 getResourceAsStream,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!