Android:即使可以在浏览器中查看文件,也可以使用java.io.FileNotFoundException

月原

我正在尝试在我的应用程序中下载图像文件,但是即使可以在浏览器中查看图像,也一直收到“ java.io.FileNotFoundException”。这是假定下载文件的代码。您可以在浏览器上测试链接

new Thread(new Runnable() {

            @Override
            public void run() {

                String filepath = Environment.getExternalStorageDirectory().getAbsolutePath();
                String sample = "https://yande.re/image/617a7bff242f2ec56ccfc84df53604fc/yande.re%20263544%20chibi%20shinomiya_himawari%20vividred_operation.jpg";
                try
                {   
                  URL url = new URL(sample);
                  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                  urlConnection.setRequestMethod("POST");
                  urlConnection.setDoOutput(true);                   
                  urlConnection.connect();                  


                  File SDCardRoot = new File(Environment.getExternalStorageDirectory(),"Yandere/Wallpapers");
                  SDCardRoot.mkdirs();
                  String filename="downloadedFile.jpg";   
                  Log.i("Local filename:",""+filename);
                  File file = new File(SDCardRoot,filename);
                  if(file.createNewFile())
                  {
                    file.createNewFile();
                  }                 
                  FileOutputStream fileOutput = new FileOutputStream(file);
                  InputStream inputStream = urlConnection.getInputStream();
                  int totalSize = urlConnection.getContentLength();
                  int downloadedSize = 0;   
                  byte[] buffer = new byte[1024];
                  int bufferLength = 0;
                  while ( (bufferLength = inputStream.read(buffer)) > 0 ) 
                  {                 
                    fileOutput.write(buffer, 0, bufferLength);                  
                    downloadedSize += bufferLength;                 
                    Log.i("Progress:","downloadedSize:"+downloadedSize+"totalSize:"+ totalSize) ;
                  }             
                  fileOutput.close();
                  if(downloadedSize==totalSize) filepath=file.getPath();    
                } 
                catch (MalformedURLException e) 
                {
                  e.printStackTrace();
                } 
                catch (IOException e)
                {
                  filepath=null;
                  e.printStackTrace();
                }}
        }).start();

错误:

 08-05 16:36:28.032: W/System.err(17064): java.io.FileNotFoundException: https://yande.re/image/617a7bff242f2ec56ccfc84df53604fc/yande.re%20263544%20chibi%20shinomiya_himawari%20vividred_operation.jpg
08-05 16:36:28.032: W/System.err(17064):    at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
08-05 16:36:28.032: W/System.err(17064):    at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
08-05 16:36:28.032: W/System.err(17064):    at angel.util.Downloader$1.run(Downloader.java:52)
08-05 16:36:28.032: W/System.err(17064):    at java.lang.Thread.run(Thread.java:856)
苏希尔

将您的网址字符串从更改为:

https://yande.re/image/617a7bff242f2ec56ccfc84df53604fc/yande.re%20263544%20chibi%20shinomiya_himawari%20vividred_operation.jpg

http://yande.re/image/617a7bff242f2ec56ccfc84df53604fc/yande.re%20263544%20chibi%20shinomiya_himawari%20vividred_operation.jpg

实际上将“ https”更改为“ http”,它应该可以工作。这项更改对我来说是有效的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

java.io.FileNotFoundException:系统找不到指定的文件

来自分类Dev

java.io.FileNotFoundException错误消息

来自分类Dev

Android - java.io.FileNotFoundException

来自分类Dev

Android-java.io.FileNotFoundException

来自分类Dev

读取.csv文件时出现java.io.FileNotFoundException

来自分类Dev

java.io.FileNotFoundException:找不到文件configuration.yml

来自分类Dev

java.io.FileNotFoundException:打开失败:EROFS(只读文件系统)

来自分类Dev

BitmapFactory无法解码流:Android中的java.io.FileNotFoundException

来自分类Dev

使用Jsoup时java.io.FileNotFoundException

来自分类Dev

Android URL连接java.io.FileNotFoundException

来自分类Dev

提交时出现java.io.FileNotFoundException

来自分类Dev

资产文件目录,提供java.io.FileNotFoundException蚀

来自分类Dev

java.io.FileNotFoundException,打开失败:ENOENT

来自分类Dev

关键工具错误:java.io.FileNotFoundException

来自分类Dev

java.io.FileNotFoundException中的访问被拒绝

来自分类Dev

java.io.FileNotFoundException即使imageView可以显示图片

来自分类Dev

Android:即使sdcard中存在文件,java.io.FileNotFoundException

来自分类Dev

ContextConfiguration抛出java.io.FileNotFoundException:

来自分类Dev

java.io.FileNotFoundException:找不到文件configuration.yml

来自分类Dev

java.io.FileNotFoundException:打开失败:EROFS(只读文件系统)

来自分类Dev

使用Jsoup时java.io.FileNotFoundException

来自分类Dev

无法在Android中解码流java.io.FileNotFoundException?

来自分类Dev

关键工具错误:java.io.FileNotFoundException

来自分类Dev

如何避免此java.io.FileNotFoundException?

来自分类Dev

创建FileInputStream时java.io.FileNotFoundException

来自分类Dev

IO 异常 java.io.FileNotFoundException: (文件名太长)

来自分类Dev

inputStream 给出 java.io.FileNotFoundException

来自分类Dev

System.IO.FileNotFoundException:找不到文件

来自分类Dev

Opencsv 中的 java.io.FileNotFoundException

Related 相关文章

  1. 1

    java.io.FileNotFoundException:系统找不到指定的文件

  2. 2

    java.io.FileNotFoundException错误消息

  3. 3

    Android - java.io.FileNotFoundException

  4. 4

    Android-java.io.FileNotFoundException

  5. 5

    读取.csv文件时出现java.io.FileNotFoundException

  6. 6

    java.io.FileNotFoundException:找不到文件configuration.yml

  7. 7

    java.io.FileNotFoundException:打开失败:EROFS(只读文件系统)

  8. 8

    BitmapFactory无法解码流:Android中的java.io.FileNotFoundException

  9. 9

    使用Jsoup时java.io.FileNotFoundException

  10. 10

    Android URL连接java.io.FileNotFoundException

  11. 11

    提交时出现java.io.FileNotFoundException

  12. 12

    资产文件目录,提供java.io.FileNotFoundException蚀

  13. 13

    java.io.FileNotFoundException,打开失败:ENOENT

  14. 14

    关键工具错误:java.io.FileNotFoundException

  15. 15

    java.io.FileNotFoundException中的访问被拒绝

  16. 16

    java.io.FileNotFoundException即使imageView可以显示图片

  17. 17

    Android:即使sdcard中存在文件,java.io.FileNotFoundException

  18. 18

    ContextConfiguration抛出java.io.FileNotFoundException:

  19. 19

    java.io.FileNotFoundException:找不到文件configuration.yml

  20. 20

    java.io.FileNotFoundException:打开失败:EROFS(只读文件系统)

  21. 21

    使用Jsoup时java.io.FileNotFoundException

  22. 22

    无法在Android中解码流java.io.FileNotFoundException?

  23. 23

    关键工具错误:java.io.FileNotFoundException

  24. 24

    如何避免此java.io.FileNotFoundException?

  25. 25

    创建FileInputStream时java.io.FileNotFoundException

  26. 26

    IO 异常 java.io.FileNotFoundException: (文件名太长)

  27. 27

    inputStream 给出 java.io.FileNotFoundException

  28. 28

    System.IO.FileNotFoundException:找不到文件

  29. 29

    Opencsv 中的 java.io.FileNotFoundException

热门标签

归档