2 回答
TA贡献1893条经验 获得超10个赞
readAllBytes 是在 java10+ 中引入的,android 还没有那么深入。源代码兼容性是关于哪些 Java 语言功能可用。可以单独配置使用哪个JVM;安装JDK8并指向eclipse。然后 getAllBytes 应该消失。
TA贡献1830条经验 获得超9个赞
我相信这是您正在寻找的功能:
/**
* Copies all available data from in to out without closing any stream.
*
* @return number of bytes copied
*/
private static final int BUFFER_SIZE = 8192;
public static int copyAllBytes(InputStream in, OutputStream out) throws IOException {
int byteCount = 0;
byte[] buffer = new byte[BUFFER_SIZE];
while (true) {
int read = in.read(buffer);
if (read == -1) {
break;
}
out.write(buffer, 0, read);
byteCount += read;
}
return byteCount;
}
添加回答
举报