Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从网站下载图片_Android_Web_Download - Fatal编程技术网

Android 从网站下载图片

Android 从网站下载图片,android,web,download,Android,Web,Download,网上某处有一个网站。它在第一页有一张图片(在某个文件夹中)。 从那个地方下载这张图片到安卓设备需要什么?a需要要求站点所有者做什么?可能是把这张照片放到某个文件夹里。。等等。我需要密码/登录吗? 请帮忙。我以前没做过。 也许我需要一个链接来了解更多。。谢谢。首先,请看这里: 我认为,如果图片在浏览器中可见,您可以访问它 那么有趣的部分是 URL url = new URL("http://yoursite.com/" + imageURL); //you can write

网上某处有一个网站。它在第一页有一张图片(在某个文件夹中)。 从那个地方下载这张图片到安卓设备需要什么?a需要要求站点所有者做什么?可能是把这张照片放到某个文件夹里。。等等。我需要密码/登录吗? 请帮忙。我以前没做过。 也许我需要一个链接来了解更多。。谢谢。

首先,请看这里:

我认为,如果图片在浏览器中可见,您可以访问它

那么有趣的部分是

URL url = new URL("http://yoursite.com/" + imageURL); //you can write here any link
File file = new File(fileName);
除此之外:

/* Open a connection to that URL. */

    URLConnection ucon = url.openConnection();

    ...

    ByteArrayBuffer baf = new ByteArrayBuffer(50);
    int current = 0;
    while ((current = bis.read()) != -1) {
       baf.append((byte) current);
    }
现在您有了原始映像的字节[],可以写入文件系统:

/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
file
是可以自由设置的文件对象,例如

String fileName = "/data/data/image_downloader/image001.png"

  File file = new File(fileName);
看链接!它包含一个完整的示例

编辑

有关目录列表,请参见:

别忘了看看有用的WebView(使用它的一个实例做很多事情):


谢谢!还有一个问题。如果图片每天都不一样,并且有唯一的名称,但文件夹总是一样的,那该怎么办?每次我都需要非常新的图片。@Foenix你们不能访问你们并没有URL的东西,HTTP的第一条规则,因此,你需要知道如果我理解正确,我需要所有的名称-位置和图片名称。你是在问是否有可能浏览de folder以获得文件名吗?但我认为你需要激活目录列表,然后才能包含所有文件的列表(就像你可以使用浏览器一样,有时间你可以“不允许目录列表,对吗?)