2016-04-14 48 views
-1

請,需要幫助。我有這個錯誤java.io.FileNotFoundException:http://news.yandex.ru/quotes/1507.png(可以通過瀏覽器看到),同時將其保存到我的內部存儲。 這是我的方法:通過網址保存圖像到內部存儲

無效downloadGraph(字符串link){ 嘗試{

   URL url = new URL(link); 
       HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 
       urlConnection.setRequestMethod("GET"); 
       urlConnection.setDoOutput(true); 
       urlConnection.connect(); 

       File dbDirectory = new File(mctx.getFilesDir().getAbsolutePath()+ File.separator+"yqimages/"); 
       if(!dbDirectory.exists())dbDirectory.mkdir(); 
       String fname=link.substring(link.lastIndexOf("/")+1,link.length()); 
       File file = new File(dbDirectory, fname); 
       FileOutputStream fileOutput = new FileOutputStream(file); 
       InputStream inputStream = urlConnection.getInputStream(); 

       byte[] buffer = new byte[1024]; 
       int bufferLength; 

       while ((bufferLength = inputStream.read(buffer)) > 0) { 
        fileOutput.write(buffer, 0, bufferLength); 
       } 
       fileOutput.close(); 
      } catch (final Exception e) { 
       e.printStackTrace(); 
      } 
} 

你可以寫信給下載的方法\保存這個特定的圖像(如上圖所示)?任何幫助表示讚賞! 得到它!問題不在代碼中,它在圖像https://news.yandex.ru/quotes/1507.png中。出於某種原因,這張照片無法保存,而其他照片則無法保存。它與「httpS://」有關嗎?

+0

確定你正在使用android - 應該在標籤中指定,而不是浪費我們的時間 – gpasch

回答

0

here解釋所有關於下載和保存圖像在android中。

並且不要忘記在讀取和寫入外部存儲器的Menifest中添加權限。

+0

謝謝,已經找到解決方案,更改urlConnection.setDoOutput(false);訣竅。反正! –

+0

確實很棒.... :) –

相關問題