日期:2014-05-16 浏览次数:20746 次
String fname = "c:\\itanger.gif";//要入库的文件 File f = new File(fname); FileInputStream fin = new FileInputStream(f); tad.setImage(Hibernate.createBlob(fin));
public void doGet(HttpServletRequest request,HttpServletResponse response){ User user=(User)session.load(User.class, new Integer(1)); Blob photo=user.getPhoto(); InputStream in=photo.getBinaryStream(); OutputStream out=response.getOutputStream(); byte [] buf=new byte[1024]; int len; while((len=in.read(buf))!=-1){ out.write(buf, 0, len); } in.close(); out.close(); }