且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

URL - Android中图像文件的FileNotFoundException

更新时间:2023-02-23 19:17:08

我尝试这个,它的工作正常。谢谢。

i try this and its work fine. Thanks.

URL url = new URL(fileURL);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/caldophilus.jpg");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();