......
DataInputStream iStrm = conn.openDataInputStream();
byte imageData[];
//如果已知图片尺寸
if (length != -1) {
imageData = new byte[length];
// 读取图片数据至imageData数组
iStrm.readFully(imageData);
// 图片尺寸未知
} else {
ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
int ch;
while ((ch = iStrm.read()) != -1)
bStrm.write(ch);
imageData = bStrm.toByteArray();
bStrm.close();
}
//创建图片
image = Image.createImage(imageData, 0, imageData.length);
......