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;
}
添加回答
舉報