try {
URL url = new URL("http://dantri.com.vn/xa-hoi.rss");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream is = new BufferedInputStream(url.openStream());
OutputStream fos = new FileOutputStream("/sdcard/xa-hoi.rss");
byte[] buffer = new byte[1024];
int bufferLenght = 0;
while((bufferLenght = is.read(buffer)) != -1){
fos.write(buffer, 0, bufferLenght);
}
fos.close();
fos.flush();
is.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
LogCat:03-05 05:11:35.620:W / System.err(3437):java.io.FileNotFoundException:http://m.dantri.com.vn/xa-hoi.rss。
此问题是将网址“ dantri.com.vn/xa-hoi.rss”更改为“ m.dantri.com.vn/xa-hoi.rss”
请帮我!。谢谢大家。
最佳答案
确保您已在清单中编写了以下内容。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />