【发布时间】:2012-04-20 01:25:50
【问题描述】:
下面的方法将 InputStream 中的数据作为字符串返回,该字符串将使用 StringBuilder 构造
String getBytes(InputStream is) throws IOException{
StringBuilder sb = new StringBuilder();
int ch;
while ((ch = is.read()) != -1) sb.append((char)ch);
is.close();
return sb.toString();
}
但此方法不适用于图像数据。最好的解决方案是构建类似的方法,但返回字节 [] 而不是字符串。谁能告诉我怎么做?
【问题讨论】:
标签: java image byte inputstream