//byte[] buf = new byte[2048];  这个时候可以插入.txt文件,但插入不进去图片不知道为什么
byte[] buf = new byte[204800];  //这个时候去可以插入图片,原因不知道为啥
int len = 0;
if((len = bis.read(buf,0,buf.length)) != -1) {  //如果为bis.read()没有参数的话,.txt,.jpg等都插入不进去,不知道为什么
   os.write(buf, 0, len);
   os.flush();
}

解决方案 »

  1.   

    bis是什么,BinarayInputStream,当然要带参数。不然不知道到底读取多少字节啊。
      

  2.   

    byte[] buf = new byte[2048];
    bis.read(buf,0,buf.length)就是说我要读取上面定义的那个buf个字节是吗?而且是只读取这些????
      

  3.   

    每次读取的最多的字节数,在使用完os,最好调用flush将缓存中的数据全部输入到目标位置
    如果向数据库中插入图片,最好采用PreparedStatement进行,不知道你这里的os是写到那里去了
      

  4.   

        OutputStream out = response.getOutputStream();
         Product item = Product(); 
         java.sql.Blob picture = item.getPicture();
        InputStream in = picture.getBinaryStream();
    byte[] b = new byte[512];
    int len = in.read(b);
    while(len != -1){
    out.write(b, 0, len);
    len = in.read(b);
              }
        //试一下