gpt4 book ai didi

android - SDK23 中缺少 ByteArrayBuffer

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:16 25 4
gpt4 key购买 nike

更新 android SDK 22->23 时 org.apache.http.util.ByteArrayBuffer 不再存在 - 是否有替代品或者这是一个错误?

最佳答案

这个答案可能有点晚,但另一种方法是将 ByteArrayBuffer 替换为 ByteArrayOutputStream 并使用字节数组,如下所示:

使用 ByteArraybuffer 的代码示例:

   BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(buffer.toByteArray());

现在,使用ByteArrayOutputStream:

     BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
//We create an array of bytes
byte[] data = new byte[50];
int current = 0;

while((current = bis.read(data,0,data.length)) != -1){
buffer.write(data,0,current);
}

FileOutputStream fos = new FileOutputStream(file);
fos.write(buffer.toByteArray());
fos.close();

嗯,我希望这对你有用。

关于android - SDK23 中缺少 ByteArrayBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32138739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com