在几个URL上获取FileNotFoundException。试着下载

时间:2012-09-14 23:02:19

标签: java android file download inputstream

我正在为Android设备开发一个下载所有应用程序,由于某些原因,只有少数网址通过抛出FileNotFoundException来解决我的问题。我打印出URL并将其复制到我的浏览器,它在那里工作正常,所以我不知道问题是什么。

例外:

W/System.err(14261): java.io.FileNotFoundException: 
http://feedproxy.google.com/~r/BillBurr/~5/pCkxUgHf5tY/MMPC_9-9-12.mp3

代码(减去大多数异常处理):

URL u = new URL(uri);

HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
c.setReadTimeout(readTimeout);

int totalSize = c.getContentLength();
InputStream in = null;
try {
     in = c.getInputStream(); // Exception problem here 

     byte[] buffer = new byte[1024];
     int len1 = 0;
     ................

1 个答案:

答案 0 :(得分:2)

只需删除c.setDoOutput(true);即可。 DOH!

欢呼声。