Android中从以下网址保存图像时只读的错误 [英] Read-Only error when saving image from URL in Android

查看:112
本文介绍了Android中从以下网址保存图像时只读的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Web URL保存图像中的Andr​​oid应用程序但是当我运行它,日志猫抛出一个异常,并称其只读。我不知道怎么回事。

I am trying to save an image from a web URL in an android application however when I run it, the log cat throws an exception saying its "read only". I don't know whats going on.

下面是我的下载类:

  public class ImageDownload {

public static void downloader(String imageURL, String fileName) { 
        try {
                URL url = new URL("http://www.exampleurl.com/" + imageURL); 
                File file = new File(fileName);


                URLConnection con = url.openConnection();

                InputStream is = con.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();

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

}
}

当我运行这一点,这是我从logcat中得到:

When I run this, this is what I get from the logcat:

DEBUG/Downloader(22112): Error: java.io.FileNotFoundException: /example.gif (Read-only file system)

任何帮助将是巨大的。谢谢你。

Any help would be great. Thank you.

推荐答案

尽量保存到/sdcard/example.gif

try saving to /sdcard/example.gif

这篇关于Android中从以下网址保存图像时只读的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆