gpt4 book ai didi

java - 无法解析符号 'ByteArrayBuffer'

转载 作者:搜寻专家 更新时间:2023-11-01 07:51:24 25 4
gpt4 key购买 nike

因此,在我的应用程序中有一个 WebView,其中包含我想在单击按钮时保存的图像。为此,我使用了这段代码:

import org.apache.http.util.ByteArrayBuffer;

public void DownloadFromUrl(String fileName) { //this is the downloader method
try {
URL url = new URL(wv2.getUrl()); //you can write here any link
File file = new File(fileName);
Canvas canvas = new Canvas();
wv2.draw(canvas );

long startTime = System.currentTimeMillis();
Log.d("ImageManager", "download begining");
Log.d("ImageManager", "download url:" + url);
Log.d("ImageManager", "downloaded file name:" + fileName);
URLConnection ucon = url.openConnection();

InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);

ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}

FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
Log.d("ImageManager", "download ready in"
+ ((System.currentTimeMillis() - startTime) / 1000)
+ " sec");

} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}

其中 wv2 是 WebView。奇怪的是,我不能再这样做了,并且在我的导入语句中出现错误 Cannot resolve symbol 'ByteArrayBuffer'

最佳答案

org.apache.http 在最新的 SDK 中被删除,这就是导入失败的原因。

请注意,您在此代码中不需要 ByteArrayBuffer,您可以改用 ByteBuffer,或者从 bis 写入 fos,如下所示:

            InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
FileOutputStream fos = new FileOutputStream(file);

int current = 0;
while ((current = bis.read()) != -1) {
fos.write(current);
}

fos.close();

关于java - 无法解析符号 'ByteArrayBuffer',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34557599/

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