如何把一张  图片(例如路径为c://49.bmp)转成二进制 我要得到byte[] bs  的值,求高手指教 谢谢
                               
                          InputStream in = null;
Blob image = null;
String imgFile = "c://49.bmp";
in = new FileInputStream(imgFile);
image = Hibernate.createBlob(in);

InputStream in2=image.getBinaryStream();
    byte[] bs=new byte[in2.available()];
//image = Hibernate.createBlob(in);
System.out.println(image.length());
// byte[]  bs = image.getBytes(1, (int) image.length());
BASE64Encoder encoder = new BASE64Encoder();
String picStr=encoder.encode(bs);// 返回Base64编码过的字节数组字符串

解决方案 »

  1.   

    这个我用过,可以用ByteArrayOutputStream流的 toByteArray方法
      

  2.   

    ByteArrayInputStream bais = new ByteArrayInputStream(InputStream is);
    byte[] bs = bais.toByteArray();
      

  3.   

    已解决  3Q啦  还是谢谢  各位了。!!
    代码如下:
    BufferedInputStream in3 = new BufferedInputStream(new FileInputStream("c://blog.bmp"));
      ByteArrayOutputStream out = new ByteArrayOutputStream(1024);   
        
      byte[] temp = new byte[1024];   
      int size = 0;   
      while ((size = in3.read(temp)) != -1) {   
      out.write(temp, 0, size);   
      }   
      in3.close();   
      byte[] content = out.toByteArray();