URL - FileNotFoundException for image file in Android

前端 未结 6 1732
再見小時候
再見小時候 2020-12-17 04:04

I\'m trying to get a image from particular URL but it throwsFileNotFoundException. If I try to open the url from my browser, i can see the images. Please help.

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 04:39

    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();
    

提交回复
热议问题