如果服务器发来的字节流没有作任何标记,只是在发完一次数据后flush(),则在客户端可以用inputStream.available()来判断流的长度,但一定要在调用read()至少一次之后,不然就只能得到零值。 实例代码如下: // 通过BLOB对象获得一个InputStream InputStream input = imageblob.getBinaryStream(); // ServletOutputStream用来传输数据, OutputStream out = response.getOutputStream(); int firstChar = input.read(); int length = input.available(); // 将其转换成二进制数据 byte [] image = new byte [length];image[ 0 ] = ( byte )firstChar; int len = 0 ; while ((len = input.read(image, 1 ,length - 1 )) != - 1 ) ... { out.write(image, 0, len);} out.flush();out.close();